• (nodebb)

    Does the program even have a console to write stuff to ?

  • Naomi (unregistered)

    assert '!' == '~';

  • SS (unregistered)

    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.

  • 516052 (unregistered)

    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.

  • RLB (unregistered)

    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?

  • dpm (unregistered)

    Sorry, but you'd have to pay me to read that. Waaaaaaay too close to being real work.

  • Scott (unregistered)

    Also, what if ccdi is null?

    And facility

  • akozakie (unregistered)

    some of the logic used… You keep using that word...

  • Carl Witthoft (google) in reply to Scott

    Falicitations, Scott: you got WHOOSHED

  • Totally Agree (unregistered) in reply to dpm

    These industrial devices don't happen to be trash compactors, do they? That's too much ugly code for a Monday.

  • Loren Pechtel (unregistered)

    Another hypothesis:

    This is a minimum-effort port from a decompile of another language.

  • Officer Johnny Holzkopf (unregistered)

    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.

  • (nodebb)

    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.

  • MaxiTB (unregistered)

    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.

  • jochem (unregistered)

    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."

  • (nodebb) in reply to zomgwtf

    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.

  • (nodebb)

    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.

  • MyName (unregistered) in reply to zomgwtf

    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.

  • EPIC Hindi (unregistered)
    Comment held for moderation.
  • (nodebb) in reply to MaxiTB

    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).

Leave a comment on “Terned Around About Nullables”

Log In or post as a guest

Replying to comment #:

« Return to Article