Jump to content

Most ridiculous piece of code


iyeager

Recommended Posts

Coding Without Comments

Alternately

"Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?"

Brian Kernighan, "The Elements of Programming Style", 2nd edition, chapter 2
Link to comment

Coding Without Comments

Alternately

"Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?"

Brian Kernighan, "The Elements of Programming Style", 2nd edition, chapter 2

I remember

Ritchie, Thompson, Plougher and Kernighan all talking about the merits of obscurity when trying to protect IP. It's an important lesson to bear in mind when considering how "easy" you want to your code for those who might follow...

Of course, we all DID know that Ritchie and Thompson left open some back doors, even though they denied it for many, many years.
Link to comment

I've seen this plenty. To help me sleep at night, I pretend that the case structure once held functional value and through the course of because someone just forgot to refactor.

To be honest, I think that's what happen with the one I shared too - I like to think, based on the whitespace around it, there was once some uber difficult logix going on there. At least, that's what I have to beleive.

Link to comment

The original code is a unique opportunity to "do the right thing" and still wind up obfuscating your code. It is possible, and some think advisable, to actually add comments to your regex using (?#comment). This sounds good, and the added bonus is that it quadruples the size of your regex, diluting the information content. Of course since self-perceived cleverness scales directly (exponentially?) with the length of a regex you get to feel much better about yourself.

Some of the "best" code I have written is for working around the occassional (cough) bugs in LV, often the smallest ones lead to the most interesting workarounds. For example I once needed to know if the output terminal of a compound arithmetic node was inverted, a small oversight in the scripting properties. I'll describe the fix (which only gets better each time I look at it):

Copy the Compound Aritmetic Node.

Create a New VI

Paste the Node into the BD

Shrink to one terminal

Check for inverted input (at least you can do that), remove invert if needed

Change mode to add

Wire constant 1 to input

Create indicator

Run the new VI

Check output, if it == -1 then the output is inverted

Resume scripting..

The best part, I'll wager most people either do not realize you can invert the output and the few that do, never do.

Link to comment

> ...I once needed to know if the output terminal of a compound arithmetic node was inverted, a small oversight in the scripting properties...

For those that are curious, this scripting deficiency has been reported to R&D as CAR 197239, and is slated to be fixed in the next LabVIEW release.

Link to comment

For those that are curious, this scripting deficiency has been reported to R&D as CAR 197239, and is slated to be fixed in the next LabVIEW release.

I was probably the only person keeping score on that one at home, but a little birdie told me that this was fixed as an afterthought to a second CAR which is probably much more useful to many of us. I do not want to jinx anything though.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.