Slashdot is powered by your submissions, so send in your scoop


Forgot your password?

Does Coding Style Matter? 479

theodp writes "Over at Smashing Magazine, Nicholas C. Zakas makes the case for Why Coding Style Matters. 'Coding style guides are an important part of writing code as a professional,' Zakas concludes. 'Whether you're writing JavaScript or CSS or any other language, deciding how your code should look is an important part of overall code quality. If you don't already have a style guide for your team or project, it's worth the time to start one.' So, how are coding style guidelines working (or not) in your world?"
This discussion has been archived. No new comments can be posted.

Does Coding Style Matter?

Comments Filter:
  • by Anonymous Coward on Saturday October 27, 2012 @02:57PM (#41790667)

    ... and it makes version control diffs shorter and to the point.

  • by Anonymous Coward on Saturday October 27, 2012 @03:08PM (#41790801)

    Tabs indent, spaces align. Your code should look equally good no matter whether tabstop is three characters or eight.

  • by Teckla ( 630646 ) on Saturday October 27, 2012 @03:25PM (#41790943)

    I use tabs because anyone can set the width to whatever they like (2, 4 or 8 spaces usually).

    There still exists a lot of tools that assume tab stops are 8, without the ability to change them. Some people use those tools by choice, some people use those tools by mandate.

  • Style is Substance (Score:5, Informative)

    by afgam28 ( 48611 ) on Saturday October 27, 2012 @03:31PM (#41790995)

    The best article that I've ever read on coding style is Style is Substance [] by Ken Arnold.

    I won't repeat what he has to say here, because he explains it better than I could. But I wish that more programming languages would follow what he is advocating, because we waste way too much time arguing about braces and tabs.

  • by Animats ( 122034 ) on Saturday October 27, 2012 @03:36PM (#41791025) Homepage

    Just use Artistic Style [] for C and its derivatives C++, C#, and Java. I usually set it for "--style=ansi", but that's a project preference. External code is run through Artistic Style before use. This way, everyone knows the indentation is consistent.

    For Python, of course, there are few formatting options, so this isn't an issue. Dreamweaver will indent HTML. Javascript remains a problem.

  • by slashping ( 2674483 ) on Saturday October 27, 2012 @03:43PM (#41791083)
    Yes, most editors allow you to change, but I also use command line tools like grep, less, or diff, and they just send the tabs to the terminal which interprets them the standard way with a spacing of 8. Sure, I can set my terminal to change the tab width, but if I then grep some other sources, such as the Linux kernel tree, in the same terminal window, it gets messed up again. The solution is obvious and simple. Just leave the tab width at 8, and everything works fine, even it uses a mix of tabs and spaces for formatting.
  • KR (Score:5, Informative)

    by SpaghettiPattern ( 609814 ) on Saturday October 27, 2012 @04:09PM (#41791311)
    Kernighan and Ritchie stands for an exemplary coding style. It's spirit can be transferred to more modern languages. It was thought of with readability and screen economy in mind.

    My does:
    • Never omit braces for conditions and loops.
    • Spaces instead of tabs. This is a holy war which I have fought with myself. Stated with tabs but after years of persevering I realised spaces had less issues.
    • In related projects, choose one style and stick with it.
    • Let the IDE do the code formatting for you.
    • At any cost, avoid the order of members to be significant.
    • If you need fancy formatted comment then your design may need a review.
    • Design your software to be a set of modules and develop each module as pure as you can. Solving one problem well reflects in the code you produce.
    • Divide your compilation units in units containing data structure definitions and units containing processing code. That also makes your code more readable.
    • Learn from better programmers and become a better programmer every day.
    • Avoid the pitfall of cryptic programs. The more people can read you code the better it can be maintained.

    My don'ts list is getting shorter and shorter. Most programmers have reasons why they produce the code the way they do. Lack of experience should be met with understanding and appreciation for improvements.

  • by icebraining ( 1313345 ) on Saturday October 27, 2012 @04:25PM (#41791421) Homepage

    one of these guys is using Comic Sans as his coding font, as he's dyslexic and it helps him

    Has he looked into fonts designed to help dyslexics, like Gill Dyslexic [] and Open-Dyslexic []?

  • by rgbrenner ( 317308 ) on Saturday October 27, 2012 @04:45PM (#41791543)

    no, it's you who broke the formatting by mixing whitespace characters.

    and you don't want to type "| expand -t4", so you're going to make a mess of the commit log, make diff a mess, and force everyone else to run everything through indent.

    It's sloppy and inconsistent.. and you're making it harder for everyone else on your team because of your laziness.

Would you people stop playing these stupid games?!?!?!!!!