1. DLP Flash Christmas Competition + Writing Marathon 2024!

    Competition topic: Magical New Year!

    Marathon goal? Crank out words!

    Check the marathon thread or competition thread for details.

    Dismiss Notice
  2. Hi there, Guest

    Only registered users can really experience what DLP has to offer. Many forums are only accessible if you have an account. Why don't you register?
    Dismiss Notice
  3. Introducing for your Perusing Pleasure

    New Thread Thursday
    +
    Shit Post Sunday

    READ ME
    Dismiss Notice

C++ compilers.

Discussion in 'Tech Support' started by Oz, Sep 7, 2010.

  1. Nefar

    Nefar Seventh Year

    Joined:
    Apr 1, 2007
    Messages:
    287
    I'm a completely new CS student ("noob coder"), and in the interest of learning good coding habits without having to unlearn bad ones, what is a good alternative to using tabs? Just pressing space a set number of times whenever I want to indent? That seems like it would add up to a lot of wasted time in the long run versus using the tab key.
     
  2. KrzaQ

    KrzaQ Denarii Host DLP Supporter

    Joined:
    May 9, 2008
    Messages:
    1,404
    Location:
    Poland
    I usually use tabs, but I've never participated in a group project so...

    Anyhow, most good editors allow user to select tab behaviour (tabs or spaces, if spaces - how many). Notepad++, Qt Creator.
     
  3. Militis

    Militis Supreme Mugwump

    Joined:
    Jun 24, 2008
    Messages:
    1,683
    Location:
    Online
    e-texteditor (paid, unfortunately) and gedit are also on the list. (gedit for Windows works rather well, all things considered. I still prefer using it in a Linux environment however.)

    I don't know the "standard" for how many spaces to do for an indent, but I like 4. 8 wastes a lot of whitespace, and if you have a small monitor it makes code wrap way too much (or run off the screen if you don't know about the wonders of wordwrap).
     
    Last edited: Sep 10, 2010
  4. Perspicacity

    Perspicacity Destroyer of Worlds ~ Prestige ~ DLP Supporter

    Joined:
    Nov 27, 2007
    Messages:
    1,022
    Location:
    Where idiots are not legally permitted to vote
    High Score:
    3,994
    You're right about the justification for no tab-indent, Militis. A second reason is that it mucks up the way I use editor commands such as vim's control-V, the "killer-keystroke" making vim my code editor of choice. (I use xemacs for everything else).

    Our coding standard uses two-space indentations, something partly driven by how a couple of us do substantial development on laptops--i.e., I don't have access to my dual 30" monitors, as on my desk at work--and two spaces works much better than 4 or 6 with our 80-character-line soft limit: lines shouldn't go longer than 80 characters, including white space. Two spaces isn't quite enough to visually line stuff up easily when one has many nested loops, though, so we also comment closed brackets when it's not obvious what's going on. Within vim, the '%' keystroke is also invaluable--it jumps from one brace/parentheses to its match.

    Code:
    for ( i=0; i<=10; ++i ) { 
      statement 1;
      statement 2;
      ...
      if ( i==5 ) { 
        do {
          stuff;
        } while ( stuff_to_do() ); 
      } [b]// if[/b]
    } [b]// for[/b]
    
    To help with laptop work, we append the opening brace for a block after the statement, like
    Code:
    if ( cond ) {  // opening brace is on the line
      ...
    }
    
    rather than
    Code:
    if ( cond ) 
    {  // opening brace on new line, which eats a whole row
      ...
    }
    
    (or variants of the latter). It's not something to get overly hung up over, though on any code project with more than 2 people, at least one person will invariably take on the role of Standards Nazi, enforcing whatever formatting rules you come up with.
     
    Last edited: Sep 10, 2010
  5. Speakers

    Speakers Backtraced

    Joined:
    Feb 7, 2010
    Messages:
    697
    Frankly, I don't care much for fancy text editors either but I do love tab-indenting. It's something I've gotten used to over the years. I guess I haven't worked on projects with members using largely different platforms/editors and I can see where the problem might come from.

    Although is tab-indenting vs space-indenting really a noob vs experience debate?

    edit: I do use the latter style pers but that's probably because I'm a huge Microsoft fan. and yeah, I've seen people who're experienced with vim, it really is a nice editor once you get used to it.
     
    Last edited: Sep 10, 2010
  6. Perspicacity

    Perspicacity Destroyer of Worlds ~ Prestige ~ DLP Supporter

    Joined:
    Nov 27, 2007
    Messages:
    1,022
    Location:
    Where idiots are not legally permitted to vote
    High Score:
    3,994
    To be honest, I was being a little facetious with my comment about tab-indent vs. spaces. Formatting minutiae is something that I don't get all that hung up over, though I do get a little annoyed when my favorite keystrokes don't do what I'd like them to (especially when fixing someone else's crapcode). If what you do works and you're productive with it, that's what you should use. In particular, if you're one of many on a single project, where you all use the same editors/environments, or if you're the only one on a project, the tab/space thing isn't an issue.

    In general, you need an editor powerful enough to make you effective, whatever your level of experience. Not every editor is for everyone. Most hardcore folks I know, those with hundreds of thousands of lines of code under their belts, tend to move toward powerful editors such as the ones I mentioned above, editors with a pretty steep learning curve, though capable of doing some things no other editors I know of can do.
     
  7. Inverarity

    Inverarity Groundskeeper

    Joined:
    Mar 5, 2008
    Messages:
    362
    I love vim (have never been able to force myself into the mindset to "get" emacs), and have done large coding projects with it, but I have to say that if you are working on a project with lots of files, especially if you're doing object-oriented programming (i.e., Java or C++), it is totally worth it to climb the learning curve to master an IDE (like Eclipse). Tracing references, refactoring, and debugging alone is worth the price of admission. (And yes, you can do all those things with vim or emacs, but the commands to do so become increasingly arcane, when a GUI IDE lets you do it with a right-click.)

    So yeah, it's nice to be able to code with a simple text editor with syntax highlighting, but you'll be much more productive with a real IDE. (If you learn to use it, that is. I've known programmers who basically used their IDE for syntax highlighting and not much else.)