Click here to Skip to main content
14,424,458 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
 
GeneralRe: Cleverest Code of the Day! Pin
den2k8825-Jan-18 3:43
professionalden2k8825-Jan-18 3:43 
GeneralRe: Cleverest Code of the Day! Pin
Richard Deeming25-Jan-18 9:50
communityengineerRichard Deeming25-Jan-18 9:50 
GeneralRe: Cleverest Code of the Day! Pin
englebart25-Jan-18 3:02
professionalenglebart25-Jan-18 3:02 
GeneralRe: Cleverest Code of the Day! Pin
MSBassSinger25-Jan-18 8:41
professionalMSBassSinger25-Jan-18 8:41 
JokeRe: Cleverest Code of the Day! Pin
raddevus24-Jan-18 11:02
communityengineerraddevus24-Jan-18 11:02 
GeneralRe: Cleverest Code of the Day! Pin
Ehsan Sajjad24-Jan-18 19:57
professionalEhsan Sajjad24-Jan-18 19:57 
GeneralRe: Cleverest Code of the Day! Pin
Ehsan Sajjad26-Jan-18 1:42
professionalEhsan Sajjad26-Jan-18 1:42 
GeneralRe: Cleverest Code of the Day! Pin
Member 798912225-Jan-18 0:18
MemberMember 798912225-Jan-18 0:18 
Remimds me of the code generated by a compiler I once knew:

This was in the days of the superminis, very much CISC. This machine (called ND-500) had a "LoadIndex [register] [indexvalue] [min] [max]" instruction: If the value at [indexvalue] was not between [min] and [max], a exception was generated.

This compiler could (optionally) verify all array indexing, using this instruction, but not quite in the straightforward way that you might think. A disassembly showed something like this

LOAD R4, indexvalue
COMP R4, min
JUMPLT error
COMP R4, max
JUMPGT error
% everything is OK, go ahead
...
error:
LOADINDEX R4, R4, 0, -1 % no legal range, will unconditionally generate exception

Generating six instructions to replace a single one can be meaningful, but hardly when one of the six is the instruction you want to replace... I was working in the company making both the CPU and the compiler, so I went to the compiler guy for an explanation. He insisted that since index check was an option, it should not change any code generated, only add code: The index check is like a debugging aid that you might turn off in a production build, and the production version should be exactly the code you debugged, minus the debug features. With the option off, the first instruciton (LOAD R4, indexvalue) was generated. Turn it on, and you get the five additional instructions.

Needless to say: Even though his argument sort of sounds plausible, I strongly disagreed with him. First, index checking is not a debug feature; you keep it on in the production version. Second: Given an option set, the compiler should be free to the best code for that selection of options, ignoring other option sets (think of optimization options!)

After much arguing, he agreed to rather generate

LOAD R4, indexvalue
LOADINDEX R4, R4, min, max

... two instructions is better than six. But he stuck to his principles: I never got him to generate a singel LOADINDEX.
JokeRe: Cleverest Code of the Day! Pin
Ehsan Sajjad25-Jan-18 1:42
professionalEhsan Sajjad25-Jan-18 1:42 
GeneralRe: Cleverest Code of the Day! Pin
obermd25-Jan-18 4:14
Memberobermd25-Jan-18 4:14 
GeneralRe: Cleverest Code of the Day! Pin
Ehsan Sajjad25-Jan-18 4:16
professionalEhsan Sajjad25-Jan-18 4:16 
GeneralRe: Cleverest Code of the Day! Pin
Gary Huck25-Jan-18 4:49
MemberGary Huck25-Jan-18 4:49 
GeneralRe: Cleverest Code of the Day! Pin
Ehsan Sajjad25-Jan-18 5:10
professionalEhsan Sajjad25-Jan-18 5:10 
GeneralRe: Cleverest Code of the Day! Pin
rnbergren25-Jan-18 5:14
Memberrnbergren25-Jan-18 5:14 
GeneralRe: Cleverest Code of the Day! Pin
Ehsan Sajjad25-Jan-18 5:19
professionalEhsan Sajjad25-Jan-18 5:19 
GeneralRe: Cleverest Code of the Day! Pin
patbob25-Jan-18 6:42
Memberpatbob25-Jan-18 6:42 
GeneralRe: Cleverest Code of the Day! Pin
Ehsan Sajjad25-Jan-18 7:24
professionalEhsan Sajjad25-Jan-18 7:24 
GeneralRe: Cleverest Code of the Day! Pin
Gerry Schmitz25-Jan-18 10:22
mveGerry Schmitz25-Jan-18 10:22 
GeneralRe: Cleverest Code of the Day! Pin
James Lonero25-Jan-18 14:07
MemberJames Lonero25-Jan-18 14:07 
GeneralRe: Cleverest Code of the Day! Pin
Dan Sutton28-Jan-18 9:39
MemberDan Sutton28-Jan-18 9:39 
GeneralRe: Cleverest Code of the Day! Pin
Ehsan Sajjad28-Jan-18 9:49
professionalEhsan Sajjad28-Jan-18 9:49 
GeneralRe: Cleverest Code of the Day! Pin
Dan Sutton28-Jan-18 9:52
MemberDan Sutton28-Jan-18 9:52 
GeneralThought of the Day Pin
OriginalGriff24-Jan-18 6:01
communityengineerOriginalGriff24-Jan-18 6:01 
GeneralRe: Thought of the Day Pin
Marc Clifton24-Jan-18 6:06
communityengineerMarc Clifton24-Jan-18 6:06 
GeneralRe: Thought of the Day Pin
Mike Hankey24-Jan-18 6:39
professionalMike Hankey24-Jan-18 6:39 

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.