• My Name * (unregistered) in reply to Code Slave
    Code Slave:
    Nagesh:
    Chelloveck:

    I used to work in a C shop. All C, all the time. One of the old-timers complained when I used the '?:' conditional operator.

    x = (a > b) ? a : b;

    Like that, only with meaningful variable names.

    In my view, it is more sense making to have more lines of code for future maintenance guy to understand that code. The more cryptic code is difficult to understand. I am sure mr Atwood, mr [Ed]Spolsky and mr Skeet (A.S.S) team will get this point.

    Sadly, I find my self agreeing with someone identifying them self as Nagesh. Perhaps it's time to rethink my life. HOWEVER, the advantage that using the '?' operator does is it saves a bunch of space in your source file. The disadvantage being it makes the intentions of the statement cryptic. Kind of like the classic strcpy trick in C

    while (*dest = *(src++)) ;

    Perfectly valid... efficient... and it is important to understand how and WHY it works. However, so does:

    strcpy(dest,src);

    If you are wanting to a dick measuring contest by having the smallest most compact source code - great. But if you want to make it understandable to the next guy who's going to have to maintain it long after you are gone, don't be a dick. (full disclosure: I used to be one of those dicks)

    We're not working on PDP-11's any more. Memory and processor time is cheep. People's time is not. Chances are the processor is going to optimise:

    if (a > b)
    {
        x = a;
    }
    else
    {
        x = b;
    }
    

    the same way as the original example, any way.

    I would much rather see something like

      case1 ? action1
    : case2 ? action2
    : case3 ? action3
    ; 

    (with sensible naming, given the context of the solution)

    than a verbose string of if-elsif-else's. Why? Because they are far more likely to fit on a single screen. Because it is trivial to add another case by simply adding another row. In other words, this construct maps cases to actions, and the implementation makes that clear. I don't care that the compiler will turn both into the same code. This is easier make sense of, even if it is not as "easy to read".

    Funny symbols are not the enemy. You can pretty much ignore them -- context makes their semantics transparent. Unnecessary explicit sequencing is the enemy.

  • not frits either (unregistered) in reply to not frits at all

    It may mean comparison, where you filter from all possible values from x^n those where it n equals a number from 0 to ∞, adding those values up. I’ve heard mathematicians do not think unlike Haskell programmers.

  • C (unregistered) in reply to Jack
    Jack:
    Image4.Visible := t = 1;
    OK I don't know Pascal or Delphi, so I'm just going to take a guess at the array syntax, but why wouldn't you simply

    Image[t].Visible := 1;

    after clearing the entire array, of course?

    Actually, no. The original code is better, it doesn't change visibilities unneedingly. Therefore, no flicker. [see image 5 in the following "Error'd"! :D]

    Also, no need for a separate list of images yet, but i suppose having many (more) buttons and many images might warrant it, but it still would be something like "for x:=1 to N do Image[x].Visible := t = x;".

    PS Your array syntax is fine, your boolean isn't. :p

  • Kevin Cline (unregistered) in reply to D-Coder

    Pascal was perfect in every way except that it was nearly unusable. C++ was horrible, but it was usable.

  • Someone (unregistered) in reply to anon

    You must be new here. I became convinced long ago that typos and grammar errors must be intentionally inserted, because there isn't a single article without them.

  • not another Nagesh (unregistered) in reply to Nagesh

    If you cannot wrap your little twisted head around a simple concept such as the Ternari operator, please stop calling yourselves a programmer (never mind a software engineer).

    Thanks for playing.

  • Gumpy Gus (unregistered)

    Needless to say it could be boiled down to one simple loop, as you can easily iterate through the form fields and set the flags, something like:

    for i := 1 to MainForm.FieldCount do with Form.Fields[ i ] do if Name = 'Button' + I2S( i ) then Visible := t = i;

Leave a comment on “The Long Glow”

Log In or post as a guest

Replying to comment #:

« Return to Article