Click here to Skip to main content
15,884,388 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: Which code you suggest? Pin
jibalt19-Aug-13 23:31
jibalt19-Aug-13 23:31 
AnswerRe: Which code you suggest? Pin
Jonathan C Dickinson29-Jul-13 22:07
Jonathan C Dickinson29-Jul-13 22:07 
GeneralRe: Which code you suggest? Pin
jibalt19-Aug-13 23:34
jibalt19-Aug-13 23:34 
AnswerRe: Which code you suggest? Pin
PIEBALDconsult30-Jul-13 5:24
mvePIEBALDconsult30-Jul-13 5:24 
AnswerRe: Which code you suggest? Pin
DarkChuky CR30-Jul-13 6:48
DarkChuky CR30-Jul-13 6:48 
GeneralRe: Which code you suggest? Pin
johannesnestler1-Aug-13 4:27
johannesnestler1-Aug-13 4:27 
GeneralRe: Which code you suggest? Pin
DarkChuky CR1-Aug-13 5:44
DarkChuky CR1-Aug-13 5:44 
GeneralRe: Which code you suggest? Pin
johannesnestler1-Aug-13 23:26
johannesnestler1-Aug-13 23:26 
Very good points. I feel we may have quite similar experiences. I also worked for the last 7 years on Windows CE and Embedded with .NET CF and native code. On Win CE 5 (which was a big step already) we had the 32 MB memory limit per process - How funny, that TODAY one of these old CE 5 devices "showed up" on my office-desk with a "pretty" .net machine-visualization on it - customer (programmer) is telling me that he ran into problems... Guess what? -> Out of Memory!

So I totally agree with your points about "Juniors" - And I think we as programmers, will face the same story again, after someone comes up with the idea of the next IThing and want's to play tetris on it.

When I was a C++ programmer and realized that I didn't do so much optimizing and inlinig and what not any more, I thought: "Finally we arrived where Memory and CPU perf. is "enough" for my use-cases". But when I startet my first embedded device project a few years later, it was the old story again...

So I never mean't that Performance/Memory consumption doesn't matter, and in reality I think about it on every line of code I write (a habit hard to discard if you started programming in a time where it was "expensive"). - Like you said: a good Add On even in todays projects.

But I think that today the "code" has to do so much more than just "crunch the numbers". We write code in patterns, abstractions, with test support, support for different plattforms or frameworks, for services, devices, serialization scenarios, for easy maintenance, for whatever is needed on the project at hand, and only sometimes there are performance or memory constraints now (when I started this was ALWAYS one of the most important things - "unreadable guru code for safing 2 bytes? - no problem").

It may be a project where RAD and easy "junior-flipping" is wanted - so go for .NET, easy constructs, no optimazitions where deep knowledge is needed (a case where perf. of foreach vs. for should not matter). But another time you will have todo something very "fast" or "cheap on memory", then comes the time to optimize algorithms and code for specific tasks. But if I'm on a CE device, found a perfomance/memory bottleneck, I would hardly think about optimizing the IL code - I'd go for a native solution (maybe C++) and use Interop to call it (if marshalling perfomance impact is not a problem). Because from my experience the "biggest" gain on using native code, is to circumvent the GC...
Of course using unsafe code can be an alternative, and optimizing perf/memory is the only good reason one may do it (apart from legacy code calling needs)- he would be silly to use a foreach loop (to stick with our example) there...

Btw. If you look at Microsofts latest project examples for the new platforms (WP8, Metro ...) about performance/memory heavy tasks (Imaging...) you will see the same approach - one project for RAD designing the GUI in .NET, and another one for the performance/memory optimized code written in NATIVE C++ (not CLR).

So in the end I think you are right, what separates the "pros from the amateurs" is the knowledge about such little things like for vs. foreach, break, string-allocation,... and even more in a complex "framework" like .NET with various programming languages and "flavours". This makes the sometimes little but crucial difference in projects like the one you descriped (I imagine you smiling after they messed it up because not following your recommendations Poke tongue | ;-P ).

But it happens often to me that readabillity and "pattern awareness" of code does matter more than "pure" perfomance, because code will run on hardware with more memory than StartTrek authors thought is "much" in the 90's...

Kind regards Johannes
AnswerRe: Which code you suggest? Pin
TheGreatAndPowerfulOz30-Jul-13 10:18
TheGreatAndPowerfulOz30-Jul-13 10:18 
AnswerRe: Which code you suggest? Pin
johannesnestler1-Aug-13 4:04
johannesnestler1-Aug-13 4:04 
AnswerRe: Which code you suggest? Pin
Vasudevan Deepak Kumar2-Aug-13 8:29
Vasudevan Deepak Kumar2-Aug-13 8:29 
GeneralMisaligned elephants Pin
Matthew Faithfull22-Jul-13 2:10
Matthew Faithfull22-Jul-13 2:10 
GeneralRe: Misaligned elephants Pin
Richard Deeming22-Jul-13 11:34
mveRichard Deeming22-Jul-13 11:34 
GeneralRe: Misaligned elephants Pin
Matthew Faithfull22-Jul-13 11:54
Matthew Faithfull22-Jul-13 11:54 
GeneralRe: Misaligned elephants Pin
ExcellentOrg22-Jul-13 21:25
ExcellentOrg22-Jul-13 21:25 
GeneralRe: Misaligned elephants Pin
enhzflep23-Jul-13 19:51
enhzflep23-Jul-13 19:51 
GeneralRe: Misaligned elephants Pin
Matthew Faithfull23-Jul-13 23:03
Matthew Faithfull23-Jul-13 23:03 
GeneralRe: Misaligned elephants Pin
enhzflep23-Jul-13 23:39
enhzflep23-Jul-13 23:39 
GeneralRe: Misaligned elephants Pin
Sentenryu24-Jul-13 0:38
Sentenryu24-Jul-13 0:38 
GeneralRe: Misaligned elephants Pin
Matthew Faithfull24-Jul-13 0:55
Matthew Faithfull24-Jul-13 0:55 
GeneralRe: Misaligned elephants Pin
Sentenryu24-Jul-13 1:18
Sentenryu24-Jul-13 1:18 
GeneralRe: Misaligned elephants Pin
Matthew Faithfull24-Jul-13 1:23
Matthew Faithfull24-Jul-13 1:23 
GeneralRe: Misaligned elephants Pin
RafagaX24-Jul-13 4:41
professionalRafagaX24-Jul-13 4:41 
GeneralRe: Misaligned elephants Pin
Sentenryu24-Jul-13 6:08
Sentenryu24-Jul-13 6:08 
GeneralRe: Misaligned elephants Pin
BiggerDon24-Jul-13 2:15
BiggerDon24-Jul-13 2:15 

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.