I just tried this one with the IDE because I couldn't believe it. LOL, and this language is one of the most used.
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 ;-)
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.
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.
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.
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.
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.
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. ¯\_(ツ)_/¯
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.