wait till you see
if __name__ = "__main__":
main()
`
wait till you see
if __name__ = "__main__":
main()
`
I've always found needing to manually add a class instance parameter (i.e. self
) to every object method really weird. And the constructors being named __init__
. Not having multiple dispatch is kinda annoying too. Needing to use decorators for class methods, static methods, and abstract classes is also annoying. Now that I think about it, Python kinda sucks (even though it's the language I use the most, lol).
Nah self
is quite important. The main part of a method is to access the state of the object. self
is just the interface to it.
Guess I just prefer languages that do it this way:
class AClass {
var aProp = 0
fun aMethod() {
aProp++
}
}
Though I suppose confusion and bugs can happen when you do something like:
class AClass {
var aProp = 0
fun aMethod(aProp: Int) {
// `this.aProp` is needed to access the property
}
}
The if block is where my arg parser goes
I would put my code in a def main()
, so that the local names don't escape into the module scope:
if __name__ == '__main__':
def main():
print('/s')
main()
(I didn't see this one yet here.)
One thing I really dislike about Python is the double underscore thing, just really looks ugly to me and feels excessive. Just give me my flow control characters that aren't whitespace
Does everyone call the function of the script main? I never use main(), just call the function what the program is supposed to do, this program calculates the IBNR? The function is called calculate_IBNR(), then at the end of the script if name = 'main': calculate_IBNR(test_params) to test de script, then is imported into a tkinter script to be converter to an exe with pyinstaller
All of mine are called do_thing()
because after a few days of working on it, the scope creep always means the original name was wrong anyway.
Still better than having to create a new class just to implement
public static void main(String[] args) {}
Relevant Fireship video: https://youtu.be/m4-HM_sCvtQ
Since Java 21, this has been shortened significantly. https://www.baeldung.com/java-21-unnamed-class-instance-main
Impossible.
Only took 27 years to make the Java "Hello, world!" kinda sane.
It really doesn't. It's a scripting language, functions are there but at it's core it runs a script. The issue is that it was so easy to start with that people started doing everything in it, even though it sucks for anything past complex scripts
It is the excel of databases.
What's the difference between a "scripting" language and a "real" one?
A scripting language controls an existing binary. A non-scripting language is used to create a new binary.
Scripting languages are real. Generally people consider dynamic languages scripting languages but it's not that simple.
Sometimes I have the misfortune of working with python code written by someone else and I wonder how a language like this became anything more than a scripting language
I feel that Python is a bit of a 'Microsoft Word' of languages. Your own scripts are obviously completely fine, using a sensible and pragmatic selection of the language features in a robust fashion, but everyone else's are absurd collections of hacks that fall to pieces at the first modification.
To an extent, 'other people's C++ / Bash scripts' have the same problem. I'm usually okay with 'other people's Java', which to me is one of the big selling points of the language - the slight wordiness and lack of 'really stupid shit' makes collaboration easier.
Now, a Python script that's more than about two pages long? That makes me question its utility. The 'duck typing' everywhere makes any code that you can't 'keep in your head' very difficult to reason about.
other people's Java
I'm gonna have to disagree here, it's always a guessing game of how many layers of abstraction they've used to seemingly avoid writing any implementation code... Can't put the code related to "bicycles" in the Bicycle
class, no, that obviously goes in WheeledDeviceServiceFactoryBeanImpl
that's in the 'utils' package.
Enough of that crazy talk - plainly WheeledDeviceServiceFactoryBeanImpl
is where the dependency injection annotations are placed. If you can decide what the code does without stepping through it with a debugger, and any backtrace doesn't have at least two hundred lines of Spring boot, then plainly it isn't enterprise enough.
Fair enough, though. You can write stupid overly-abstract shit in any language, but Java does encourage it.
Depends on how lazy I am at the moment.
main.py
or did you not read the manual?
Welcome to Programmer Humor!
This is a place where you can post jokes, memes, humor, etc. related to programming!
For sharing awful code theres also Programming Horror.