Click here to Skip to main content
15,881,877 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: 21,662 Pin
StM0n23-Sep-11 11:09
StM0n23-Sep-11 11:09 
JokeRe: 21,662 Pin
Sander Rossel24-Sep-11 10:37
professionalSander Rossel24-Sep-11 10:37 
JokeRe: 21,662 Pin
AspDotNetDev24-Sep-11 11:00
protectorAspDotNetDev24-Sep-11 11:00 
GeneralRe: 21,662 PinPopular
Sander Rossel24-Sep-11 11:40
professionalSander Rossel24-Sep-11 11:40 
GeneralRe: 21,662 Pin
AspDotNetDev24-Sep-11 12:22
protectorAspDotNetDev24-Sep-11 12:22 
GeneralRe: 21,662 Pin
Sander Rossel24-Sep-11 12:50
professionalSander Rossel24-Sep-11 12:50 
GeneralRe: 21,662 Pin
AspDotNetDev24-Sep-11 14:16
protectorAspDotNetDev24-Sep-11 14:16 
GeneralRe: 21,662 Pin
BobJanova26-Sep-11 4:07
BobJanova26-Sep-11 4:07 
The HIGHLANDER one is a bit of a joke, I think, and generally for switching between one and many it's fine to use a literal 1 – it's never going to be anything different and logically it could not be. But yes, generally, constants are good, particularly if you otherwise write a comment.

const WOTSITS_PER_THING = 13;
...
function Things(){
 var wotsits = getWotsitNumberFromSomewhere();
 return {things: wotsits / WOTSITS_PER_THING; leftover: wotsits % WOTSITS_PER_THING };
}

... is much better than

function Things(){
 var wotsits = getWotsitNumberFromSomewhere();
 return {things: wotsits / 13; leftover: wotsits % 13}; // 13 wotsits per thing
}


Personally, I like no comments – in an ideal world the code is clear enough. (No comments and unreadable code is really, really bad, though! Zero comments doesn't mean I like your code.) Because we're working in a fairly low level procedural language, though, you often need to comment higher level algorithms (particularly array or matrix related ones that get lost in a pile of loop code). XML header documentation is nice for the autocompletion but it is very easy for it to get out of date if you modify the code, and (like all comments) it isn't checked by the compiler. I would probably add it to the public interface at the end, given the choice (though for the projects I've released on here I was too lazy to do that).
GeneralRe: 21,662 Pin
Sander Rossel26-Sep-11 8:01
professionalSander Rossel26-Sep-11 8:01 
JokeRe: 21,662 Pin
AspDotNetDev26-Sep-11 8:35
protectorAspDotNetDev26-Sep-11 8:35 
GeneralRe: 21,662 Pin
Sander Rossel26-Sep-11 8:38
professionalSander Rossel26-Sep-11 8:38 
GeneralRe: 21,662 Pin
BobJanova26-Sep-11 22:25
BobJanova26-Sep-11 22:25 
GeneralRe: 21,662 Pin
witm553-Oct-11 22:24
witm553-Oct-11 22:24 
GeneralRe: 21,662 Pin
Sander Rossel4-Oct-11 8:45
professionalSander Rossel4-Oct-11 8:45 
GeneralRe: 21,662 Pin
witm554-Oct-11 10:43
witm554-Oct-11 10:43 
GeneralRe: 21,662 Pin
Sander Rossel4-Oct-11 10:53
professionalSander Rossel4-Oct-11 10:53 
GeneralRe: 21,662 Pin
TorstenH.26-Sep-11 3:23
TorstenH.26-Sep-11 3:23 
GeneralPower beep Pin
Lutosław22-Sep-11 1:44
Lutosław22-Sep-11 1:44 
JokeRe: Power beep Pin
Julien Villers22-Sep-11 22:06
professionalJulien Villers22-Sep-11 22:06 
GeneralRe: Power beep Pin
Lutosław22-Sep-11 22:53
Lutosław22-Sep-11 22:53 
GeneralRe: Power beep Pin
Sander Rossel24-Sep-11 3:24
professionalSander Rossel24-Sep-11 3:24 
GeneralRe: Power beep Pin
Pravin Patil, Mumbai25-Sep-11 19:40
Pravin Patil, Mumbai25-Sep-11 19:40 
GeneralGuess it does not contains 'Contains' Pin
VallarasuS22-Sep-11 1:37
VallarasuS22-Sep-11 1:37 
GeneralRe: Guess it does not contains 'Contains' Pin
Nagy Vilmos22-Sep-11 1:46
professionalNagy Vilmos22-Sep-11 1:46 
GeneralRe: Guess it does not contains 'Contains' Pin
VallarasuS22-Sep-11 2:02
VallarasuS22-Sep-11 2:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.