Dec-23-2017, 02:06 PM
class foo(): def __init__(self, bar): self.moo = bar #technically this 'runs' #and visually someone starting out may misconstrue that attribute=parameter (bar in this case) #but self.moo is really the attribute. WHY AM I ALLOWED to name self.moo as anything I want? #what is the rationale here? It really should be self.bar = bar...and this is convention, but #nothing really stops us from changing attr to self.mooIt is extremely common in ALL languages to use attribute names that are different from the parameters that set them. Other OOP languages support "data hiding" where attributes/fields are not directly accessible. Python does not have this. In other words, using your example I could do this:
class Foo: def __init__(self, bar): self.moo = bar f = Foo() f.moo = "MOOOOOOOOO"So in Python we follow a convention where we put an underscore '_' in front of fields that shouldn't be touched:
class Foo: def __init__(self, bar): self._moo = barSo why does the language let you? Because all you're doing is assigning the value of one variable (bar) to another (self._moo). The language itself doesn't (and can't) attribute semantic meaning to variable names. It's up to you, the programmer to write clear, clean, and understandable code. And I will let you in on a little secret: lots of programmers write muddled, ugly, unintelligible code. But it works so they think they're a success.
Quote: I want to ask why do you run directly through bash? what is the advantage? I ask bc I started out coding directly through the terminal (linux) -but didn't like it. Moved to idle, and now go through geany (atom feels buiky). Any advantage to running thru bash(or terminal) and python3 vs geany (& other ides)f5???
I do the bulk of my development work with Vim and bash simply because I'm very comfortable with those tools. I use and like PyCharm, and have used Eclipse and Visual Studio for Java and C/C++/C# development as well. In this particular case, to copy and paste a little code and run it quickly, there was no reason to fire-up an IDE.