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, embarrasing 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.

There are plenty of dumb things done in SQL. Could be the coder never heard of ISNULL. Could be he came from a programming background. Could be he doesn't realize ISNULL is more efficient than a case statement. Could be a misapplication of "don't execute a function in a where clause" rule. Could be he forgot about ISNULL. Could be he's in the "Let's obsfucate this code as much as possible" club.

At least it isn't SUM(CASE WHEN cTT.Total IS NOT NULL THEN cTT.Total ELSE 0 END) as 'Total_Total'

People have become so used to using frameworks, the primitives that the framework is built on, no longer has meaning to them. It is both a shame but also a measure of the quality of the some of the frameworks being used.

Chris MeechI am Canadian. [heard in a local bar]

In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]

posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]

You have punched one of my hottest hot buttons: the tendency among far too many engineers to eschew the simple path.

My theory of the thing goes as follows: There are three stages in a software engineer's development / three types of software engineers / three phases to a life in software engineering:

1. The beginner: This engineer has little knowledge and less experience. That combination inclines him toward simplicity, for he hasn't the tools to get deep into the thickets, nor would he be confident of coming out alive. His programs tend to be easy to read, if sometimes a bit "naive."

2. The intermediate engineer: This engineer has begun to "feel his oats." He's learned quite a lot about various programming languages and fundamental algorithms, and he wants to show it off! So he embeds as much of what he "knows" in every program he writes as he possibly can. (Cf: "A Real Programmer knows every nuance of every instruction and uses them all in every Real Program.") His programs are next to illegible. After the passage of a few months, he won't want to admit to authoring them, much less maintain or debug them.

3. The senior engineer: This engineer is a grizzled, battle-scarred veteran. He's been around the block more times than you can count without taking off your booties. And while he can be a bit of a bore about those scars and how he earned them, his programs are a pleasure to read and maintain, because he's learned the virtues of simplicity. He never over-complicates a solution, because he's well aware that should it come apart under stress in a year's time, the most likely stuckee will be himself -- and remembering the rationale for excess complexity, and how to unsnarl it, is just too much like real work.

When I interview a fresh young candidate, I routinely describe the three types of engineers to him, and I ask: "Which sort of engineer do you aspire to be?" There are only two acceptable answers:

A senior engineer, wise in the ways of the bits and a staunch foe of excess complexity;

Hey, man, this engineering crap is just a stop along the way to the stars; I want to be the CEO of this place!

Food for thought.

(This message is programming you in ways you cannot detect. Be afraid.)

That is so true. The intermediate in any craft is out to proove himself and so shows off everything he knows whether it was the best solution for the problem or not. Were as the master shows simplicity and economy, doing more with less.

n. The retread: An experienced developer (in Java for instance) may come to C++ with habits that aren't good C++. Need a thingy object? "myThingy = new Thingy(1,2);" That's how you do it in Java. In C++ you have more choices. In fact, the revised example (using STL) looks very much like a Java programmer doing C++ to me.

A good point. I had a subordinate like that: a highly experienced FORTRAN 66 programmer who had done a few years in management and had only just come back to the tech side. Thought all variables should be global. Couldn't see the point of classes and objects. Linked lists and dynamically allocated memory were incomprehensible to him. He was slotted into our C++ environment and just about fell apart. It took quite a bit of work to save him from the Grim Reaper.

(This message is programming you in ways you cannot detect. Be afraid.)

Apropos of which, the antidote I've found most effective against "excess cleverness" is a year or so programming exclusively in assembly language. Just about any engineer who has an assembler-only task will quickly realize that only simple assembler programs are debuggable or maintainable...no matter how determined to show off he is!

(This message is programming you in ways you cannot detect. Be afraid.)

When you learn a couple of patterns to solve a particular problem, you have the tendency to apply it on other problems and work around the rough edges, even though it makes it unnecessarily complex.

It's because you either don't 'see' the simpler solution (never change a winning team-code), or because you are used to solve more difficult problems and have a blind spot to see the obvious (university-code).

I can't speak for every programmer off course because some people are asshats, but it's not because something looks like the instruction manual of a galaxy-class warp drive written in Greek, that it's intentionally made incomprehensible.

Yes Joe, I agree with you.
Your solucion is the best one.
I never programmed it otherwise.
Only when the size goes over some multiple of 1000 bytes
I decide to allocate heap memory.
And yes: some programmers don´t even know why.
_______________________________________

Have people gotten so accustomed to complexity that they think of only complex
solutions?

C'est la vie , i often was told that a programmer that is learning a new language (or tool) tries to use every possible function of it, anyway i always advocate for simplicity, because complex solutions usually are the hardest to mantain (or change).

There's a lazy reason for vector. The programmer doesn't have to remember "4" in the code that indexes it, because they can use vector size. (You can use sizeof of course)

Complexity like this is often a result of the engineer trying to cater for every imaginable change that could possibly be required in the future. So the engineer ends up saying, "What if we need to change these unsigned integer indexes into a list of Reticulating Splines?! Oh well, better make it some horrible templated monstrosity!"

I've said it myself. Only, replace "templated monstrosity" with "cathedral of generalized reusability"

We write more code with more complexity because languages have gotten more complex over the years, and also because we've been educated to more forms of complexity. Those various solutions deal with that complexity better.

Simple new/delete isn't the safest solution in an operator-overloaded, exception-throwing world. The smart pointer solves that issue transparently (although I'm not sure whether it deletes a single character of the array, or the entire array).

The vector<> solution allows a wider range of primatives to be used against the array, in addition to being leak-safe like the smart pointer and guaranteed to call the array version of delete.

The stack solution is probably the best, and what I would opt for, if I knew I'd never need to use any of the STL primatives on it. Besides, it doesn't run any risk of memory fragmentation like ALL of the other solutions do

We can program with only 1's, but if all you've got are zeros, you've got nothing.

If the number 4 was used somewhere else in the function (e.g. in the condition of a loop), I would have defined a const int fieldSize = 4; or something like that before the first usage. In the improbable case that the number needs to be increased, it avoids the trap of changing it only in one place and then having to look for the occasionally occurring error.

Regarding allocation on the stack I had an embarassing moment myself last week. I had created an object on the stack (didn't test how large it was), and it worked fine in debug mode. In release mode it crashed somewhere. Took some time and usage of several message boxes to find out the crash occurred in the moment the function containing the object was called. Then it dawned to me that I had stumbeld across this same problem some years ago in a different place. The stackzize was smaller in release mode. I needed to allocate that object on the heap, and voilá it worked.

We are running a Jenkins service for automatically building our projects and also our setups (with a call to Visual Studio's command line). Now, one of the setups failed. I scrutinized the output for finding the reason - but no, everything was marked fine. At least I thought so when I searched for "Fehler" (German word for "error"), since the entries were like e.g. "51 erfolgreich, Fehler bei 0," or "0 Fehler, 1 Warnungen" just everywhere. Why did it fail then?
Well, I tried the a search for "error" - and voilà here it is: "error MSB3104: Die referenzierte <Path-to-some\Other.dll>-Assembly wurde nicht gefunden..." The error message is available in a nice mixture of German and English.
Great idea: if something goes wrong, use the English term "error", otherwise use German.

I am going to be removing CC.NET from my build server and reinstalling Jenkins, then setting up a reverse proxy in IIS to point a URL at the Jenkins instance. I do not like CC.NET very much, but I do like Jenkins.

I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image.
Stephen Hawking