What Workplace Coding Practices Do You Use?
Agent_9191 asks: "Recently I've been promoted to what essentially amounts to a project lead role for every project we do, in house. Since my company has run for the past 35+ years with no form of central IT department, there has been no standards put into place for developers to abide by. One of my tasks is to set up standards in how projects will be implemented and produced. Right now I'm more concerned about trying to set up coding standards, so that any developer can jump into any part of a project and be able to figure out what's going on, without wasting a couple hours just to figure out the code. I've come across some documents in this area from a few sources (of course can't remember them off the top of my head). What practices/standards do you use in your workplace?"
I like to think of it as "don't ask, don't tell" :D
got sig?
For every conditional, you chug a beer.
For every loop, you chug a beer.
And, of course, for every save, you do a shot of tequila.
The importance of a single language standard can't be overstated. Ever since my company switched to LOGO I can understand my co-workers' code at a glance.
Outsource them all.
I'm all self-taught, so I have my own style which others tell me is impossible to make heads or tails of. The standard is: the boss promises stuff to our clients, and I have to whip it out [snicker] as fast as possible. Doesn't leave much time to make easy on those who would come after me. I jokingly call the mess of code I have to make JOB SECURITY.
"You know you're narcissistic when you quote yourself in your sigs." -- PRoPAiN!
Yeah, standards are great.....we've got lots of them :-)
-Chris
--an unbreakable toy is useful for breaking other toys--
heh
"MY APOCALYPTIC TENOR HAS NOT BEEN DISPELLED!" - T-Rex, qwantz.com
Its for wussies!
-USe tons and tons of goto statements.
-Make sure you use particular letters capped for variables of different types to make them more confusing for the losers who can't read the code and remember what each one was.
- always make calls by reference using pointers as arguments. Don't use call by values.
- Hell user other pointers that use other pointers to make things more interesting. Reassign them all over the place
- Never use a three tier model when developing client/server apps. This only creates redundancy and gets in the way of solving the problem.
- When linking to a database always use vendor specific extensions and avoid a database layer using something like odbc. It makes use of the advanced feature set by the particular RDBMS.
- Be a man! Show how much you know perl. Alot of one linners can save tons of time with exotic line switches
Oh last... make tons of money and gain job security because no one in Earth will be able to understand or work on your projects after doing all of these things. Enjoy
http://saveie6.com/
Perhaps someone broke in and fixed the code.
how to invest, a novice's guide
(copy paste as much as possible)
I prefer:
//checks to see if x is equal to 256. If it is, then the code within is executed
if x==456 then
That way, there's less chance for confusion if the code gets modified in the future.
Out of curiosity, what kind of platforms do you code for? Even my commodore 64 had 16-bit ints.
Do daemons dream of electric sleep()?
Magic numbers are the worst thing you could ever put into code. They are even worse than hungarian notation...
did you notice that the comment does not match the code?
or is there some spot in the universe where x==456 will check to see if x is equal to 256?
Er, like WHOOOSH or something.
Confucius say, "Find worm in apple - bad. Find half a worm - worse."
That line still contains an example of one of my biggest pet peeves... the use of magic numbers. Okay, so the comment explains what 456 is, but not why and makes no provision for managing changes. What if a new design had a stepper motor whose final position was 256?
Magic numbers are a reality, of course, especially when dealing with hardware. But if there's no way for the code to dynamically determine the values, the very least you can do is to define a symbolic constant, and collect the constant definitions together in one place. For example:
See how much better that is? And if the value changed to, say 100, all you have to do is modify the constant definition in one place, like:
Really, a little extra work up front goes a long way.
Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
HA!!! YOU were the guy who wrote this code I am having to work on now!!! ;-)
Even for a novice programmer, code like if(x == 456) is self-explanatory, no comments are needed.
+ 1+1+1+1+1+1)))
You're right - how could it be possible not to know what that code is doing? (The rule is, the only magic numbers allowed are -1, 0, and 1. 456 is right out.)
Okay, but that's going to get really hard to debug!
if (x == (1+1)*(1+1+1+1)*((1+1+1+1)*(1+1+1+1)*(1+1+1+1)-(1
If it compiles, ship it. If it doesn't compile, ship it. If the users complain, ignore them (they are always complaining). If the users complain moreso than normal, work all day and night and fight with QA and the admins and the VPs to get a patch in.
Repeat until app becomes unmaintainable. Repeat furthur. Repeat.
I will be giving seminars on how to implement Sisyphusian Unified Process throughout the year down at the bar. If I happen to be unconcious, please leave me be - that's my "comp time".
As someone with 20+ years of professional programming under my belt, a lot of it doing maintenance and enhancement of existing code, I'll say this: most of what's considered "coding standards" doesn't much matter. Indentation, brace positioning, type prefixes on variables, underlines vs. StudlyCaps, capitalization in general, most competent programmers can pick up on any variation quickly. The few things that count are more general:
Oh yes, comments. Well we use comments as version/history information. We have every code file and project file on a single samba-shared volume. When somebody wants to change something he/she shouts "I'M OPENING THE FILE X, DON'T TOUCH IT NOW" and he/she has done modifications he/she adds very informative comment somewhere in the file (name/date/what was done), saves file back to disk and yells "OK, FILE X IS FREE NOW"
Documents... There is no documents. Who needs those anyways? It's much more fun to code something when you really don't have any idea what its supposed to do.
Test plans? Nah, waste of time I say!
Testing? Well, somebody runs it and if it doesn't crash, it works.
I must say I'm in the best damn work place ever! And now if you please, I'll go and find some ethernet cabel to strangle myself.
You don't know what you don't know.
And Hungarian notation is soo 90's ;-)
LOAD ".SIG"
PRESS PLAY ON TAPE
disassembly can lie if the operating environment or hardware is bugged (either error or with malicious code)
the only truely trustworthy code is code hand compiled to run on a tube CPU which you have personally blown the glass and formed every tube.
Snowden and Manning are heroes.
The primary purpose of the DATA statement is to give names to constants; instead of referring to pi as 3.141592653589793 at every appearance, the variable PI can be given that value with a DATA statement and used instead of the longer form of the constant. This also simplifies modifying the program, should the value of pi change.
-- FORTRAN manual for Xerox Computers
Or you could turn it into a Web Service.
LOAD_DATA + SAVE_DATA == DESTROY_DATA??
(Yes, that's compiler implementation specific, I know...)
Alan
My favorite was the entire huge module with only one comment: /* Make sure j != 2 !!!*/
No sign of a variable named j anywhere...