- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Does the program even have a console to write stuff to ?
Admin
assert '!' == '~';
Admin
I suspect that some of the "issues" mentioned in this article may not actually be any fault of the developer. This code looks awfully like it was decompiled from a dll/exe rather than the original source code. Between the objArray1, reassignment to objArray2 and all the casting seem like compiler generated code rather than something a person might write.
For instance while the "params" feature is supported by C# language it is only a syntactic sugar and gets transformed into proper array initialization (like in the code snippet of this article) at compile time.
Admin
That's what it looks like to me as well. Although I've yet to find a decompiler that generates that sort of condition mangling.
Admin
What I want to know -- machine-generated or not -- is: why first check that PowerBoxId has a value, and then assign it to a nullable type? Surely that misses the whole point?
Admin
Sorry, but you'd have to pay me to read that. Waaaaaaay too close to being real work.
Admin
Also, what if ccdi is null?
And facility
Admin
Admin
Falicitations, Scott: you got WHOOSHED
Admin
These industrial devices don't happen to be trash compactors, do they? That's too much ugly code for a Monday.
Admin
Another hypothesis:
This is a minimum-effort port from a decompile of another language.
Admin
In what universe (except maybe IBM's) is it accaptable to prohibit characters like '!' or '~' in a password? Because none of those characters is supposed to be stored (i. e., as plain text) and/or processed by "interpreting logic", there is no reason to make up such rules. I once writelned a code confuserator for logic, its passord must be 6 characters, the frist character must be a letter, and it may only contain uppercase letters, numbers, and a selected selection of national symbols... please.
Admin
This looks like standard embedded-control-engineer-written code. Others have pointed out that it looks like decompiled code or, more likely, source-to-source translated code, but I've also seen way too much code like this written by people who could design a faster-than-light drive using only components ordered from Mouser but then taught themselves programming by trial and error, and who program by trial and error, keep fiddling with the code until it does what you want, then ship it.
Admin
GetValueOrDefault, as the name implies, returns the value of the object, or if that object is null, it returns a suitable default value. Now, for any referenece type, that can still be null. But nullable1 is a boolean (defaults to false), and nullable2 is a byte (defaults to zero).
This is incorrect. First those two types are both ValueTypes. bool? is actually Nullable<bool> and that's a struct of a bool with an additonal bool to indicate the null value.
Nullable<T> structs default to null by setting the nullable bool to true.
Admin
Damn, this is some ugly C#. It's like an embedded C developer was forced to use C#. Like John Woods said "Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."
Admin
What a coincidence, I got asked just yesterday to drop our data-driven config and start developing a ladder-logic editor. Because you know, electricians understand it.
I will be supporting @zomgwtf's idea of this just coming out of someone with expertise in firmwares or (perhaps more likely) PLCs! PLCs are god your toy languages are just jokes! We're talking about running a factory here! Real stuff! Those are true statements from more than a customer I have approached.
Admin
Ah, of course! I was trying to figure out what language the original developer was thinking in and @UserK nailed it, probably not literally ladder logic but something derived from it, my guess would be ST (structured text). It looks like they were thinking in ST while writing in C#, or had been asked to redo an ST program in C#.
In which case it's not as much of a WTF as it seems.
Admin
I write in ST. And im shocked anyone implementing this language in a non-system programming language. C# is not ment for this task, any GC language is not. PLC's are about deterministic computing. Initialise memory before, no dynamic memory use. I would love to get rid off ST in PLC's and write in ADA or Rust. Stop programming important stuff that run factories with GC languages.
Admin
GetValueOrDefault() is a method of Nullable<>, and it does return zero/false. In fact it can't directly return null since it only accepts value types (but it could return a structure containing nulls).