Popular Post iyeager Posted October 25, 2012 Popular Post Report Share Posted October 25, 2012 I was writing a login screen for a recent project that required me to verify that the password met certain criteria, i.e. at least eight characters, at least one cap, at least one number or special character, etc... I came up with the attached piece of code using regex, which, surprisingly for me, actually worked. I'm planning on leaving it this way, without any comments so when I find it five years from now I'll spend at least an hour wondering what the hell I was thinking. Anyone else have any utterly ridiculous code? Not spaghetti, just off the wall, makes no sense but works perfectly kind of code? -Ian 5 Quote Link to comment
Popular Post ShaunR Posted October 25, 2012 Popular Post Report Share Posted October 25, 2012 Anyone else have any utterly ridiculous code? Not spaghetti, just off the wall, makes no sense but works perfectly kind of code? -Ian Yup. Any application I write after 6 months has elapsed 3 Quote Link to comment
Phillip Brooks Posted October 25, 2012 Report Share Posted October 25, 2012 Coding Without Comments http://www.codinghorror.com/blog/2008/07/coding-without-comments.html 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 Quote Link to comment
mje Posted October 25, 2012 Report Share Posted October 25, 2012 Yeah, I hate regex because they're so difficult to decipher, but love them because they're so bloody powerful. Reminds me of perl code. 1 Quote Link to comment
crelf Posted October 25, 2012 Report Share Posted October 25, 2012 Yup. Any application I write after 6 months has elapsed Make that 6 weeks for me. Quote Link to comment
ShaunR Posted October 25, 2012 Report Share Posted October 25, 2012 (edited) Reminds me of perl code. That's because it is PCRE (Perl Compatible Regular Expressions). How about this for graphical programming? http://www.ioccc.org...hamano/hamano.c Edited October 25, 2012 by ShaunR 2 Quote Link to comment
crelf Posted October 25, 2012 Report Share Posted October 25, 2012 How about this gem? 1 Quote Link to comment
Phillip Brooks Posted October 25, 2012 Report Share Posted October 25, 2012 How about this gem? Getting paid by the number of nodes - Priceless... (especially when you place your signature in every VI). Quote Link to comment
John Lokanis Posted October 25, 2012 Report Share Posted October 25, 2012 Know what this does? Quote Link to comment
crelf Posted October 25, 2012 Report Share Posted October 25, 2012 Know what this does? Resolves host name? Getting paid by the number of nodes - Priceless... (especially when you place your signature in every VI). Things like that don't have a tangible effect on GOB counts, thankfully Quote Link to comment
John Lokanis Posted October 25, 2012 Report Share Posted October 25, 2012 Resolves host name? Yup. I love to see new devs scratch their head when they see that in my code... Quote Link to comment
crelf Posted October 25, 2012 Report Share Posted October 25, 2012 Yup. I love to see new devs scratch their head when they see that in my code... I'd seen it before, but the file name was a giveaway 2 Quote Link to comment
ShaunR Posted October 25, 2012 Report Share Posted October 25, 2012 (edited) How about this gem? In the same vein. Here's one I've seen before Edited October 25, 2012 by ShaunR Quote Link to comment
Val Brown Posted October 25, 2012 Report Share Posted October 25, 2012 Coding Without Comments http://www.codinghor...t-comments.html 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. Quote Link to comment
crelf Posted October 26, 2012 Report Share Posted October 26, 2012 In the same vein. Here's one I've seen before No way! Quote Link to comment
asbo Posted October 26, 2012 Report Share Posted October 26, 2012 No way! 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. Quote Link to comment
ShaunR Posted October 26, 2012 Report Share Posted October 26, 2012 No way! Yup. I think originally they were using it to invert (instead of using the primitive) and during debugging/mods changed the booleans around so it was completely redundant. 1 Quote Link to comment
crelf Posted October 26, 2012 Report Share Posted October 26, 2012 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. Quote Link to comment
jcarmody Posted October 26, 2012 Report Share Posted October 26, 2012 I ended up on the Rube Goldberg thread with this: ... just last year. Quote Link to comment
Darin Posted October 26, 2012 Report Share Posted October 26, 2012 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. Quote Link to comment
Darren Posted October 26, 2012 Report Share Posted October 26, 2012 > ...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. Quote Link to comment
Darin Posted October 26, 2012 Report Share Posted October 26, 2012 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. Quote Link to comment
Phillip Brooks Posted October 30, 2012 Report Share Posted October 30, 2012 W/R/T original post: I think that regex would be useful enough to post it on the Regular Expressions Board Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.