Click here to Skip to main content
16,017,278 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: .NET Core & (auto)binding: Is it a bug? Pin
jochance18-Jun-24 3:05
jochance18-Jun-24 3:05 
GeneralUntested Backups with IonicZip Pin
kmoorevs2-Jun-24 5:30
kmoorevs2-Jun-24 5:30 
GeneralRe: Untested Backups with IonicZip Pin
MarkTJohnson4-Jun-24 5:19
professionalMarkTJohnson4-Jun-24 5:19 
GeneralRe: Untested Backups with IonicZip Pin
kmoorevs4-Jun-24 6:49
kmoorevs4-Jun-24 6:49 
GeneralLooking at the very topmost line ... Pin
trønderen1-Jun-24 11:21
trønderen1-Jun-24 11:21 
GeneralRe: Looking at the very topmost line ... Pin
Greg Utas1-Jun-24 16:42
professionalGreg Utas1-Jun-24 16:42 
GeneralRe: Looking at the very topmost line ... Pin
Daniel Pfeffer1-Jun-24 19:57
professionalDaniel Pfeffer1-Jun-24 19:57 
GeneralRe: Looking at the very topmost line ... Pin
TNCaver4-Jun-24 5:58
TNCaver4-Jun-24 5:58 
GeneralRe: Looking at the very topmost line ... Pin
trønderen4-Jun-24 14:37
trønderen4-Jun-24 14:37 
Yet it is certainly not uncommon. I guess the most common use is to let the MSB indicate whether the remaining bits is an error code or a valid index. This is frequently used as function return values: A non-negative values is a valid function result, a negative value is an error code.

My gut feeling is that this is more common with functions defined 10 or 20 years ago than with functions defined this year. But lots of old libraries are still used. Also, coding habits die slowly.

I think there is a dividing line between "Giving a single field/value multiple meanings and uses" and "storing multiple distinct fields in a word in order to save space". The compiler can give full support for it, so that the fields addressed by distinct names, are of distinct types and have no overlap. They may be declared e.g. as a byte and as a 24-bit unsigned value. Maybe the original code designers never ever would dream of 16 million not being enough for everyone. Like those who set off a 32 bit value to represent the number of seconds since 01-01-1970 00:00:00. (There is no principal difference between an unplanned 24 bit value overflow and an unplanned 32 bit overflow.)

You may argue that a programmer should always make ample headroom for all values. I have seen programmers doing that, using 64 bit values everywhere, without ever thinking. Non-thinking programmers are no good. Around Y2K there also arose a "2038 panic", and I saw programmers argue in dead earnest that now that we are approaching a 32 bit overflow, to make sure that it doesn't happen again, we should not expand the value to 64 bits but to 128 bits.

I guess that most readers are familiar with the quote from a Xerox Fortran manual, using a DATA statement to give the value of pi as 3.141592653589793, with the additional remark. "This also simplifies modifying the program, should the value of pi change". While that statement is most certainly true, the situation is not very likely to happen.

Making common sense assumptions makes sense even in programming. And even if common sense fails a rare occasions. I could mention quite a few examples of lists of persons, names or IDs where I would never consider the situation that e.g. a database system with a maximum of 16 Mi tuples would have insufficient capacity.

I would be curious to know how may of the 15.9 million CP members have been giving one or more contributions to the form the last 12 months, writing anything anywhere on the site, and who is still a member (not counting spammers who are thrown out). I suspect that the count would suggest that a 24 bit number should be enough for everybody.
Religious freedom is the freedom to say that two plus two make five.

GeneralRe: Looking at the very topmost line ... Pin
Daniel Pfeffer4-Jun-24 20:19
professionalDaniel Pfeffer4-Jun-24 20:19 
GeneralRe: Looking at the very topmost line ... Pin
trønderen5-Jun-24 3:21
trønderen5-Jun-24 3:21 
GeneralRe: Looking at the very topmost line ... Pin
Daniel Pfeffer5-Jun-24 8:29
professionalDaniel Pfeffer5-Jun-24 8:29 
GeneralRe: Looking at the very topmost line ... Pin
jochance6-Jun-24 6:31
jochance6-Jun-24 6:31 
GeneralRe: Looking at the very topmost line ... Pin
Richard Andrew x6416-Jun-24 8:12
professionalRichard Andrew x6416-Jun-24 8:12 
GeneralBlessed endian mismatches collide with progress Pin
honey the codewitch1-Jun-24 7:30
mvahoney the codewitch1-Jun-24 7:30 
GeneralRe: Blessed endian mismatches collide with progress Pin
Ron Anders1-Jun-24 8:26
Ron Anders1-Jun-24 8:26 
JokeRe: Blessed endian mismatches collide with progress Pin
PIEBALDconsult1-Jun-24 9:22
mvePIEBALDconsult1-Jun-24 9:22 
GeneralRe: Blessed endian mismatches collide with progress Pin
trønderen1-Jun-24 11:13
trønderen1-Jun-24 11:13 
GeneralRe: Blessed endian mismatches collide with progress Pin
honey the codewitch1-Jun-24 11:33
mvahoney the codewitch1-Jun-24 11:33 
GeneralRe: Blessed endian mismatches collide with progress Pin
trønderen1-Jun-24 12:39
trønderen1-Jun-24 12:39 
GeneralRe: Blessed endian mismatches collide with progress Pin
honey the codewitch1-Jun-24 12:47
mvahoney the codewitch1-Jun-24 12:47 
GeneralRe: Blessed endian mismatches collide with progress Pin
trønderen2-Jun-24 4:32
trønderen2-Jun-24 4:32 
GeneralRe: Blessed endian mismatches collide with progress Pin
honey the codewitch2-Jun-24 4:34
mvahoney the codewitch2-Jun-24 4:34 
GeneralRe: Blessed endian mismatches collide with progress Pin
11917640 Member 2-Jun-24 1:40
11917640 Member 2-Jun-24 1:40 
GeneralRe: Blessed endian mismatches collide with progress Pin
kalberts2-Jun-24 4:34
kalberts2-Jun-24 4:34 

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.