Your Programming Language of Choice?

Discussion in 'Technical Discussion' started by Armada, Jul 24, 2008.

  1. Sik

    Sik

    Sik is pronounced as "seek", not as "sick". Tech Member
    6,719
    0
    0
    being an asshole =P
    AamirM: there's much more than indentation than can annoy. Where do braces go, how to comment, how to line up function parameters, how to write declarations, etc. Honestly the programmer should adapt to the coding style used in the project, period.

    And even then, IDEs now provide tools to reformat the entire code as you wish. Use that if you're so anal about it.
     
  2. DigitalDuck

    DigitalDuck

    Arriving four years late. Member
    4,812
    23
    18
    Lincs, UK
    TurBoa, S1RL
    <!--quoteo(post=537644:date=Dec 12 2010, 05:32 PM:name=Sik)--><div class='quotetop'>QUOTE (Sik @ Dec 12 2010, 05:32 PM) <a href="index.php?act=findpost&pid=537644"><img src="public/style_images/retro/snapback.png"></a></div><div class='quotemain'><!--quotec-->Honestly the programmer should adapt to the coding style used in the project, period.<!--QuoteEnd--></div><!--QuoteEEnd-->

    This too. Bear in mind that if you're not the only person working on a piece of code, you should (as a group) define a style, and make sure everyone sticks to it. Code in a style that isn't yours is better than code in four different styles.
     
  3. Overlord

    Overlord

    ...did we just switch realities? Moderator
    17,583
    68
    28
    Berkshire, England
    Learning Cymraeg
    You should always get in the habit of indenting no matter what language you're using, it makes your code vaguely readable no matter how bad it is if the indenting is right. I work in Python now so indenting is mandatory but I was doing this as far back as VB a decade ago =P
     
  4. Chilly Willy

    Chilly Willy

    Tech Member
    746
    0
    0
    Doom 32X
    <!--quoteo(post=537639:date=Dec 12 2010, 10:22 AM:name=AamirM)--><div class='quotetop'>QUOTE (AamirM @ Dec 12 2010, 10:22 AM) <a href="index.php?act=findpost&pid=537639"><img src="public/style_images/retro/snapback.png"></a></div><div class='quotemain'><!--quotec-->Actually, no. Tabs are a LOT more convenient and portable than spaces. Here's why. Consider you like indentation of four (4) spaces, so you indent your code with 4 real spaces. Now, your co-worker, who is also working on your code, likes indentation of 2 spaces only. So, to make the code more pleasant to his eyes, he would either have to manually remove those extra two spaces of indentation or run a formatter/indention tool. Tedious. Now, if you used tabs, all he/she would have to do is to just set the tabwidth to the amount of spaces you like. Simple, easy and portable. No manual stuff required.

    Using tabs, you're not only pleasing yourself, but others as well. Using spaces, you're only pleasing yourself.<!--QuoteEnd--></div><!--QuoteEEnd-->

    If it were ONLY hard tabs, I could live with it. Unfortunately, the majority of brain-dead editors today mix hard tabs with spaces. In your example of a tab size of 2 spaces, your typical editor will still have a hard tab of 8 and will insert 2, 4, or 6 space, then replace eight with a hard tab, then give a hard tab + 2, 4, or 6 spaces, then 2 hard tabs...

    Also, allowing a person to choose the indentation via hard tabs can make the formatting outrageous - for example, instead of 2 as you mentioned, this person uses a tab of 12... and when combined with a project made with tabs of 2, you wind up with a project that's 1000 characters wide because all 2 space tabs are now 12 wide. I run into this all the time, so often the first thing I wind up doing is a global search-and-replace on hard tabs with spaces.
     
  5. TmEE

    TmEE

    Master of OPL3-SA2/3 Tech Member
    1,726
    0
    16
    Estonia, Rapla City
    T-04YBSC-A !
    If one were to change tabs from perhaps 8 to 4 it is still quite likely everything will look completely mangled up, especially in case of ASM. I don't indent my code mostly, only when there's some confusing algos going on...

    Here's some crappy code, Nineko may like it :
    Code (Text):
    1. FOR x% = 0 TO XLENGHT% STEP 8
    2. TILE$ = "": TILE1$ = "": TILE2$ = ""
    3. FOR y% = 0 TO 15
    4. SELECT CASE EIGHTBITMODE%
    5. CASE 1
    6. FOR I% = 0 TO 7 STEP 2
    7. IF PIXELS%(y%, x% + 0 + I%) > 15 THEN PIXELS%(y%, x% + 0 + I%) = 0
    8. IF PIXELS%(y%, x% + 1 + I%) > 15 THEN PIXELS%(y%, x% + 1 + I%) = 0
    9. TILE$ = TILE$ + CHR$((PIXELS%(y%, x% + 1 + I%) AND 15) OR (((PIXELS%(y%, x% + 0 + I%) - 16) AND 15) * 16))
    10. NEXT I%
    11. CASE 2
    12. FOR I% = 0 TO 7 STEP 2
    13. IF PIXELS%(y%, x% + 0 + I%) < 16 THEN PIXELS%(y%, x% + 0 + I%) = 0
    14. IF PIXELS%(y%, x% + 1 + I%) < 16 THEN PIXELS%(y%, x% + 1 + I%) = 0
    15. TILE$ = TILE$ + CHR$((PIXELS%(y%, x% + 1 + I%) AND 15) OR (((PIXELS%(y%, x% + 0 + I%) - 16) AND 15) * 16))
    16. NEXT I%
    17. CASE 3
    18. FOR I% = 0 TO 7 STEP 2
    19. A% = PIXELS%(y%, x% + I% + 0)
    20. IF A% > 15 THEN A2% = ((A% - 16) AND 15) * 16: A1% = 0:&nbsp;&nbsp;ELSE A1% = (A% AND 15) * 16: A2% = 0
    21. B% = PIXELS%(y%, x% + I% + 1)
    22. IF B% > 15 THEN B2% = ((B% - 16) AND 15): B1% = 0:&nbsp;&nbsp;ELSE B1% = (B% AND 15): B2% = 0
    23. TILE1$ = TILE1$ + CHR$(A1% OR B1%)
    24. TILE2$ = TILE2$ + CHR$(A2% OR B2%)
    25. NEXT I%
    26. CASE ELSE
    27. TILE$ = TILE$ + CHR$((PIXELS%(y%, x% + 1) AND 15) OR ((PIXELS%(y%, x% + 0) AND 15) * 16))
    28. TILE$ = TILE$ + CHR$((PIXELS%(y%, x% + 3) AND 15) OR ((PIXELS%(y%, x% + 2) AND 15) * 16))
    29. TILE$ = TILE$ + CHR$((PIXELS%(y%, x% + 5) AND 15) OR ((PIXELS%(y%, x% + 4) AND 15) * 16))
    30. TILE$ = TILE$ + CHR$((PIXELS%(y%, x% + 7) AND 15) OR ((PIXELS%(y%, x% + 6) AND 15) * 16))
    31. END SELECT
     
  6. I learned Visual Basic as my first language, but as of now my favorite is Java.
     
  7. nineko

    nineko

    I am the Holy Cat Tech Member
    <!--quoteo(post=537872:date=Dec 13 2010, 08:45 AM:name=TmEE)--><div class='quotetop'>QUOTE (TmEE @ Dec 13 2010, 08:45 AM) <a href="index.php?act=findpost&pid=537872"><img src="public/style_images/retro/snapback.png"></a></div><div class='quotemain'><!--quotec-->Here's some crappy code, Nineko may like it :<!--QuoteEnd--></div><!--QuoteEEnd-->I do ;)

    Have some VB5 code now:
    Code (Text):
    1. Private Sub Command2_Click()
    2. Open Label1.Caption + "\" + Text1.Text For Binary As #1
    3. For I% = 0 To 1023
    4. a$ = Chr$(Stage(I%))
    5. Put #1, , a$
    6. Next I%
    7. For I% = 0 To 3
    8. If Option4(I%).Value Then Exit For
    9. Next I%
    10. 'direction
    11. a$ = Chr$(I% * 64)
    12. Put #1, , a$
    13. a$ = Chr$(0)
    14. Put #1, , a$
    15. 'x
    16. a$ = Chr$(List1.ListIndex)
    17. Put #1, , a$
    18. a$ = Chr$(0)
    19. Put #1, , a$
    20. 'y
    21. a$ = Chr$(List2.ListIndex)
    22. Put #1, , a$
    23. a$ = Chr$(0)
    24. Put #1, , a$
    25. 'perfect
    26. a$ = Chr$(List3.ListIndex \ 256)
    27. Put #1, , a$
    28. a$ = Chr$(List3.ListIndex And 255)
    29. Put #1, , a$
    30. Close #1
    31. If File1.ListIndex = -1 Then File1.Refresh
    32. End Sub
     
  8. MainMemory

    MainMemory

    Have no fear...Amy Rose is here! Tech Member
    4,374
    43
    28
    SonLVL
    To me, VB looks kind of like ASM, only more confusing.
     
  9. Travelsonic

    Travelsonic

    Member
    787
    13
    18
    The formatting on that VB code looks atrocious. :P
     
  10. Hayate

    Hayate

    Tech Member
    I know:
    68k ASM
    C, Java, I won't claim to know C++ cause I use it so rarely I forget how to do shit
    QB, VBC, VB.NET (I haven't used those three in ages)
    Python
    PHP, MySQL (does that one even count?)
    XHTML, CSS, JS
    GML (Game Maker), AHK (AutoHotkey)

    And yes I did actually program something interactive in AHK, it's an anime episode chooser I use in the lounge (Essentially the media center PC except it's not running Media Center, it's running ordinary Windows XP).
    I kind of wish there was a C-style version of AHK, because AHK is incredibly useful but the syntax is even more horrendous than Basic.

    <!--quoteo--><div class='quotetop'>QUOTE </div><div class='quotemain'><!--quotec-->Argument about tabs vs spaces<!--QuoteEnd--></div><!--QuoteEEnd-->

    Use tabs. Just... use tabs. For the reason already stated in the thread - anyone reading the code will see it with their preference of tab width.
    Also, it only takes one keystroke to backspace a tab, while it takes eight (or four if you're not hardcore) keystrokes to backspace an indentation of spaces.

    <!--quoteo--><div class='quotetop'>QUOTE </div><div class='quotemain'><!--quotec-->Argument about braces on their own line<!--QuoteEnd--></div><!--QuoteEEnd-->

    Code (Text):
    1. void main(void) {
    2. <tab>...
    3. }
    Do that, it looks so much neater.
    If you put it on its own line, the shape of the lines moves to the left for the one-character brace which is aligned with the start of the line it should be on... and then moves back over to the right for the body.
    If you put it where it should be, the shape of the line moves right for an indent... as it should.

    I've also seen people doing this:

    Code (Text):
    1. void main(void)
    2. <tab>{
    3. <tab>...
    4. }
    which is just plain wrong, the brace is not part of the body.
     
  11. Sik

    Sik

    Sik is pronounced as "seek", not as "sick". Tech Member
    6,719
    0
    0
    being an asshole =P
    Pretty much all modern IDEs and text editors will kill space-based indentation in a single stroke, so that reason is out of the way.

    And like it has been said, usually hard tabs end up mixed with spaces, making the indentation look completely wrong...
     
  12. Yuzoboy

    Yuzoboy

    Member
    113
    0
    0
    UK
    <!--quoteo(post=538140:date=Dec 14 2010, 07:22 AM:name=Hayate)--><div class='quotetop'>QUOTE (Hayate @ Dec 14 2010, 07:22 AM) <a href="index.php?act=findpost&pid=538140"><img src="public/style_images/retro/snapback.png"></a></div><div class='quotemain'><!--quotec-->
    Code (Text):
    1. void main(void) {
    2. <tab>...
    3. }
    Do that, it looks so much neater.
    If you put it on its own line, the shape of the lines moves to the left for the one-character brace which is aligned with the start of the line it should be on... and then moves back over to the right for the body.
    If you put it where it should be, the shape of the line moves right for an indent... as it should.<!--QuoteEnd--></div><!--QuoteEEnd-->

    Thats the format im trying to use now. I actually got marked down in a technical interview for using the following format:

    Code (Text):
    1. void main(void)
    2. {
    3. <tab>...
    4. }
    Apparently senior developers don't like it...
     
  13. RamiroR

    RamiroR

    Member
    355
    0
    16
    Objective-C , please don't hit me. :P

    Nah, actually C++, but I'm learning/interested in learning Objective-C.
     
  14. AamirM

    AamirM

    Tech Member
    <!--quoteo(post=538164:date=Dec 14 2010, 07:03 AM:name=Yuzoboy)--><div class='quotetop'>QUOTE (Yuzoboy @ Dec 14 2010, 07:03 AM) <a href="index.php?act=findpost&pid=538164"><img src="public/style_images/retro/snapback.png"></a></div><div class='quotemain'><!--quotec-->Thats the format im trying to use now. I actually got marked down in a technical interview for using the following format:

    Code (Text):
    1. void main(void)
    2. {
    3. <tab>...
    4. }
    Apparently senior developers don't like it...<!--QuoteEnd--></div><!--QuoteEEnd-->
    What has indentation has to do with "technical" interview? It's a matter of preference and style (unless you were given some standard/guidelines to adhere to). It's like a bunch of these senior developers (aka fags) would mark you down if you liked Coke instead of Pepsi. I want to punch these sort of interviewers.
     
  15. <!--quoteo(post=538140:date=Dec 14 2010, 02:22 AM:name=Hayate)--><div class='quotetop'>QUOTE (Hayate @ Dec 14 2010, 02:22 AM) <a href="index.php?act=findpost&pid=538140"><img src="public/style_images/retro/snapback.png"></a></div><div class='quotemain'><!--quotec-->Use tabs. Just... use tabs. For the reason already stated in the thread - anyone reading the code will see it with their preference of tab width.<!--QuoteEnd--></div><!--QuoteEEnd-->
    That only works for tabs at the beginning of a line. When tabs are used in the middle of a line, that's where it screws up (like in the disassemblies we have, some people use an editor configured for 4-space-wide tabs and they start putting 2 tabs after short mnemonics like jsr, not knowing they should be using 8-space-wide tabs).

    The only way to solve code style issues is to use a programming "language" that isn't plain text, but encoded in binary or something (an abstract syntax tree, what). An editor could show the code in whatever style you like, but that information wouldn't be part of the code itself. The downside of this is that a custom editor would be required to edit the code, you can't just use any text editor out there.
     
  16. Yuzoboy

    Yuzoboy

    Member
    113
    0
    0
    UK
    <!--quoteo(post=538282:date=Dec 14 2010, 10:13 PM:name=AamirM)--><div class='quotetop'>QUOTE (AamirM @ Dec 14 2010, 10:13 PM) <a href="index.php?act=findpost&pid=538282"><img src="public/style_images/retro/snapback.png"></a></div><div class='quotemain'><!--quotec-->What has indentation has to do with "technical" interview? It's a matter of preference and style (unless you were given some standard/guidelines to adhere to). It's like a bunch of these senior developers (aka fags) would mark you down if you liked Coke instead of Pepsi. I want to punch these sort of interviewers.<!--QuoteEnd--></div><!--QuoteEEnd-->
    Absolutely nothing is the answer. But it goes to show how far some people wil go to get the perfect candidate. Its understandable if indentation and bracket use was inconsistent but it was just because their team didnt like the style I was using as it meant they would have to "change the way they read code".
     
  17. Overlord

    Overlord

    ...did we just switch realities? Moderator
    17,583
    68
    28
    Berkshire, England
    Learning Cymraeg
    <!--quoteo(post=537923:date=Dec 13 2010, 03:51 PM:name=MainMemory)--><div class='quotetop'>QUOTE (MainMemory @ Dec 13 2010, 03:51 PM) <a href="index.php?act=findpost&pid=537923"><img src="public/style_images/retro/snapback.png"></a></div><div class='quotemain'><!--quotec-->To me, VB looks kind of like ASM, only more confusing.<!--QuoteEnd--></div><!--QuoteEEnd-->
    That's not VB, that's old-style BASIC being forced though VB5. =P VB5/6 native code is more like:

    Code (Text):
    1. Private Sub sonic_write_Click()
    2. Open RomPath For Binary As #1
    3. For Counter = sonic.LBound To sonic.UBound
    4. &nbsp;&nbsp;&nbsp;&nbsp; With sonic(Counter)
    5. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Len(.Text) < .MaxLength Then .Text = .Text & String(.MaxLength - Len(.Text), 32) '32 is the character code for space
    6. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WriteString 1, .Tag, .Text
    7. &nbsp;&nbsp;&nbsp;&nbsp; End With
    8.  Next Counter
    9.  Close #1
    10.  MsgBox "Writing complete!", vbInformation, "Sonic Text Editor"
    11. End Sub
    =P
     
  18. Glaber

    Glaber

    Has Beaten Sonic Genesis for GBA Oldbie
    Click programming.

    and Java. (only one I learned in School that I didn't get all frustrated over)