Linkers::X - Let's code in C++ , Daytrade & Daydream :)

Discussion in 'Programming' started by LinkersX, Dec 26, 2017.

  1. I have an aversion to if statements and C-style error handling.
    #11     Dec 26, 2017
    LinkersX likes this.
  2. LinkersX


    OK, so how how would you form the code?
    #12     Dec 26, 2017
  3. i960


    The idiomatic way of handling different events is to have events be enumerated values and use a switch statement. Sure modern compilers will undoubtly optimize that if cascade to a jump stable but a switch/case statement is more clear.
    #13     Dec 26, 2017
    LinkersX likes this.
  4. LinkersX


    correct... but the devil is hiding in the details ;)
    #14     Dec 26, 2017
  5. I would write code that has only one path. A switch statement is a fancy dressed up if statement that is just as ugly underneath.

    If you can't simplify your code so that there is only one path, then you're probably making it more complex than it needs to be.
    #15     Dec 26, 2017
  6. LinkersX


    ... my live was really a huge void at the time... My GF got fired at her work so she got the idea to start her own jewelry biz from our large-ish studio apt in the Metropolis towers in Jersey City...
    Ohhhh Lord, that's the last thing a devil-ish c++ developer needs, a religious self employed GF working from our apt and eye rolling me because lying in our couch and staring at the ceiling while medicating myself (green energy) because i got pain in my legs. In order to start being alive again and a little away from the house, i convinced her that it would be an awesome idea to start working in the Restaurant as a waiter/captain...

    Because money was tight at the moment, it was easy for her to go along with the idea that a senior c++ developer would be a Captain the the Legendary Casa Dante @ Journal Square...
    There i met an old waiter who was actually a millionaire by net worth. When i asked him why he still there and not in Boca Raton, his answer was this way i get away from my wife for a little bit.
    Thanks to my jolly nature and little experience from the past as a server at the legendary Saracen in East Hampton Long Island, I started enjoying being a weekend waiter @ Casa Dante. You know, a little freedom from religion, sarcastically chatting up customers and making them merry...

    like Stephan

    Last edited: Dec 26, 2017
    #16     Dec 26, 2017
  7. i960


    Not really. You're simply representing flaggable states as class variables. If you want it to be better you'd have the class user register callbacks for each particular event and dispatch as the events arrive. This is old hat stuff man.

    This is false. A switch statement results in a jump table in the compiled code. There is no multiple comparisons happening - it either hits a case or it defaults.

    Also your statement about not having more than one path, dude, code has decision logic built into it. If you write your code so that it only does *one thing* and *only that thing* you've basically codified a particular need into code rather than writing code to handle that need (and others). Your code is actually *worse* in that case because it's not general purpose but entirely "curve fitted" to the particular context-specific case you're using it for.

    Having an issue with conditionals is hands down ridiculous.
    #17     Dec 26, 2017
    algofy, IAS_LLC and LinkersX like this.
  8. LinkersX


    Problem is that Linkers::X has historical lookback into events.
    The actual decision code should be something like
    • if(e.error(7)) // 7 = 7 events back
    • {
    • if(e.broker_busy(7)){//do something ...}
    • }
    #18     Dec 26, 2017
  9. Think at a level of abstraction higher than just literal statements. An if statement is representative of a class of conditional statements. As is a switch. A switch is just a DSL for a sequence of if statements. I'm so glad you know they compile to jump tables but you're going the wrong direction in level of abstraction.

    Yes, I have problems with people using them because they write shitty state-filled code that I have to debug when I could be doing something more enjoyable.
    #19     Dec 26, 2017
  10. i960


    You're arguing against an *if statement*. Please show me your code that has no if statements (or other conditionals) in it. You either handle multiple conditions or you don't and if your code doesn't then it's trivial. If it's all hidden behind an API or another layer of abstraction then they're still there, just abstracted away. Perhaps your real issue is that you dislike low level programming contexts and you have an issue with "digging ditches."
    #20     Dec 26, 2017