Remember: Always Document Your Code

Page 2 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.

mvbighead

Diamond Member
Apr 20, 2009
3,793
1
81
I indent all my code, I *refuse* to review other code that is not indented. Lack of comments is one thing, lack of indenting... NO.

This.

Depending on the language, comments may or may not be necessary. Sometimes, just looking at the code you can see exactly what is going on. But the lack of indentation just makes every look like a great big ball of text.
 

Jaskalas

Lifer
Jun 23, 2004
36,510
10,785
136
I indent all my code, I *refuse* to review other code that is not indented. Lack of comments is one thing, lack of indenting... NO.

Wouldn't it be possible to run the code through a script / macro / whatever that would auto indent it for you? Assuming it has all its brackets closed.
 

torpid

Lifer
Sep 14, 2003
11,631
11
76
Modern IDEs generally can auto-format your code and put proper indentation. Maybe you should do it just for the peace of mind, Squirrel.
 

Possessed Freak

Diamond Member
Nov 4, 1999
6,045
1
0
Wouldn't it be possible to run the code through a script / macro / whatever that would auto indent it for you? Assuming it has all its brackets closed.

If I am asked to review code, then I would consider all of it suspect including braces being opened/closed.

Plus depending on the language, there could be multiple lines for a single command which should also be indented to indicate it is the same command. Add in single line if statements, and other oddities, I am NOT writing a script to fix sloppy code that I am reviewing!
 

Red Squirrel

No Lifer
May 24, 2003
71,312
14,085
126
www.anyf.ca
What he is saying is that you can open the file in nearly ANY text editor nowadays and have 'one-click' auto-formatting, so you can fix that code really easily.

Oh right, yeah, could probably do that. At least make the code more readable then I can fix the rest of the mess. Back when I coded that my mindset was "I'll never go back to this code again". Obviously, this is false when it comes to coding.
 

Ns1

No Lifer
Jun 17, 2001
55,420
1,600
126
y7Hm9.jpg

I love this pic and actually passed it around to the devs.
 

Red Squirrel

No Lifer
May 24, 2003
71,312
14,085
126
www.anyf.ca
It's called job security.

No comments, obscure variable names, and no indentation :D

And run the code through a program that removes all the returns and spaces.

A C++ program can technically be turned into a single line of code and it will still compile. At least I think it can... not sure about the preprocessor though.

That would be funny to do that to a 1mil lines of code app. D:
 

Train

Lifer
Jun 22, 2000
13,599
90
91
www.bing.com
very few languages actually need linebreaks.

We run all our production JS and CSS through a compressor. replaces long, descriptive variable names with single letters, strips all whitespace, carriage returns and comments.

Makes the code a lot smaller, saves bandwidth, and has actually been shown to compile faster.
 

rh71

No Lifer
Aug 28, 2001
52,844
1,049
126
It's called job security.

No comments, obscure variable names, and no indentation :D

What would really happen if they needed to let you go and you needed to train someone or you wouldn't get severence? You'd need to take them through your apps and show them this and that. You're not going to be saved because you didn't comment code.
 

Alienwho

Diamond Member
Apr 22, 2001
6,766
0
76
What would really happen if they needed to let you go and you needed to train someone or you wouldn't get severence? You'd need to take them through your apps and show them this and that. You're not going to be saved because you didn't comment code.
Yeah but if you're not going to be saved then you have no incentive to help this person through the code and train them. You squander their training period and don't teach them anything. Then if the company wants your help you charge astronomical consulting fees to teach the new guy the code.
 

sao123

Lifer
May 27, 2002
12,656
207
106
//the following block of code really shouldnt work correctly
//but it does


//dont ever touch it
 

rh71

No Lifer
Aug 28, 2001
52,844
1,049
126
Yeah but if you're not going to be saved then you have no incentive to help this person through the code and train them. You squander their training period and don't teach them anything. Then if the company wants your help you charge astronomical consulting fees to teach the new guy the code.

I thought they could withhold severance if you don't train them properly. At our company I think we are given a couple weeks to a month to do that. They don't just throw you out with security.
 
Last edited:
Aug 26, 2004
14,685
1
76
found the other day in a SQL proc, this particular part selects work orders to do something with

--Arbeit macht frei

:D
 
Aug 26, 2004
14,685
1
76
another good one that I found recently was --John's cool new way to create column headings on the fly, stop reading if you don't want your mind blown

and of course stuff like, --not sure why this works, but it does so oh well
 

xanis

Lifer
Sep 11, 2005
17,571
8
0
very few languages actually need linebreaks.

We run all our production JS and CSS through a compressor. replaces long, descriptive variable names with single letters, strips all whitespace, carriage returns and comments.

Makes the code a lot smaller, saves bandwidth, and has actually been shown to compile faster.

Minification FTW