Error IB API

Discussion in 'Automated Trading' started by Leopard9, Sep 25, 2024.

  1. I just tried this one with the IDE because I couldn't believe it.
    LOL, and this language is one of the most used.
     
    #41     Sep 27, 2024
  2. spy

    spy

    Believe it... you can write messy code in any language. It's an academic exercise and I'd ask why it wasn't written like this instead:

    Code:
    --- wrong.py    2024-09-27 07:53:31.702187130 -0400
    +++ right.py    2024-09-27 07:53:10.789880237 -0400
    @@ -12,10 +12,10 @@
             self._data = data
         def set_color(self, color: str):
    -        self._data['color'] = color
    +        self._data = color
         def print_data(self):
    -        print(self._data.get('color'))
    +        print(self._data)
    orange = Fruit()
    orange.set_color("orange")

    Just to mess with people's heads? You should check out this book, it's full of things like that.

    Soon you'll start enjoying the simplicity of Perl ;-)
     
    Last edited: Sep 27, 2024
    #42     Sep 27, 2024
    d08 likes this.
  3. I don't need to read about programming anymore.
    My days of looking for jobs have finished, fortunately.

    There are so many memes about Python that one can reply every single time with a joke.

    103337054b70ccf07eb3a1f0a60a836a.jpg
     
    #43     Sep 27, 2024
    spy likes this.
  4. spy

    spy

    Oh... yeah, that's definitely a shortcoming IMHO. Absolutely hate that whitespace is code. But I've learned to live with it. Just another day at the office.

    In a perverse way it's helpful because you can spot who is a beginner by simply examining how they've sent their code to you. IOW you don't have to bother reading beyond their formatting.
     
    #44     Sep 27, 2024
  5. spy

    spy

    I'm disappointed to hear this. IDK if you've seen this one, but maybe it can help put the fun back in to reading.
     
    #45     Sep 27, 2024
    Drawdown Addict likes this.
  6. LISP!!! No fucking way.
     
    #46     Sep 27, 2024
  7. spy

    spy

    What they probably really meant to write was something more like this:

    Code:
    --- old.py      2024-09-27 08:56:34.699970193 -0400
    +++ new.py      2024-09-27 09:00:00.395286603 -0400
    @@ -8,8 +8,9 @@
    import datetime
    class Fruit:
    -    def __init__(self, data = {"color":"unkown"}):
    +    def __init__(self, data = dict() ):
             self._data = data
    +        self._data['color'] = 'unknown'
         def set_color(self, color: str):
             self._data["color"] = color
    But, like I said... sloppy code in any language. Oh well; there's always Perl.
    [​IMG]
     
    Last edited: Sep 27, 2024
    #47     Sep 27, 2024
    d08 likes this.
  8. The meme pointed the example that in any other language when you create two independent instances of an object what you should get is a plain record with default values.

    In Python what you get is a piece of shit that shares the same values for all objects within the same script. That itself is a simple excuse to ditch the language all together. So much for OOP.

    I know what you are trying to do, you hardcode default values in the constructor to avoid the issue. Simply because the langauge is shit and doesn't do it for you.
     
    #48     Sep 27, 2024
  9. spy

    spy

    This isn't true. The author of the meme simply highlights the subtle difference between operators. This happens in all languages... you have to know the language (at least some theory) intimately or you'll end up in these kinds of situations all the time. You can confuse operators in any language.

    IDK what the issue you're point out is. The default value simply needs to be set in the proper place. If you understand what the static keyword does in C you'll understand why the bug exists.

    The bottom line is it can take a long time to gain that intimate familiarity w/ any programming language. So, it may be wise to stick with one for a while before diving head first into another.

    A class in programming languages and/or automata theory can help though. This is why I suggest reading "the little schemer". It builds understanding from the ground up.

    ¯\_(ツ)_/¯
     
    Last edited: Sep 27, 2024
    #49     Sep 27, 2024
    d08 and -Orion like this.
  10. Ok boy, I'll let you carry on by yourself.

    Simply notice that I never pointed anything about yourself, it was always about the language, and you are quick to become passive aggressive and recommend classes to others. Like if needed them.
     
    #50     Sep 27, 2024
    spy likes this.