Python has main. Kinda at least. It is not enforced but highly recommend. if __name__ == '__main__' i = 0 # i is global variable print("Hello World", i) * It is easy to tell whether we should run that particular python directly or not. * Stops arbitrary code execution during imports. If you are going to implement if name main. I suggest going further and move all your code to main function and only call main() from if name main. Like this def main(): i = 0 # i is local variable print("Hello World") if __name__ == '__main__' main() It will add an advantage on top of if name main, that is you won't have global variable which results in not so fun bugs. There are a couple more advantages which I haven't touch. I highly recommend watching this video by mCoding: [https://youtu.be/g\_wlZ9IhbTs](https://youtu.be/g_wlZ9IhbTs)


And by highly recommend we mean you either do is, or you'll find a python's head in your bed


Oh you can already find one there 😈


Finally I can get blowjob with the head in the bed


many believe that there is a god, but if there was, i am certain we have killed him


Why are you the way that you are


How i love this __ syntax__


Makes you think twice before messing with the private parts heh


"The private parts" meaning "the thing every program should have like we just discussed"?


Why isn't there a neater main syntax? If everyone does that it would make a heck of a lot more sense to standardize it to new unique syntax


Nah, this syntax (ugly only because of the __ in my opinion) is actually very useful because you can do fancy things with it...


Nah, you'd usually have a normal python script as your main and import from other modules. This main only helps if you're working within a single file.


It is still useful because of two main reasons. If you have multiple python files and one has if name main. You can tell which script you should run directly. Without if name main you script will have global variables which could lead to some not so fun bugs. Slightly better explanation of both these points: https://youtu.be/g_wlZ9IhbTs


the if name syntax has nothing to do with global variables. It simply allows you to write sections of code which will not run if the module is imported. It is standard practice and should be done, but in many many cases removing it will change nothing in how the program will run


It does in a way. I didn't explain my point all the way but if you watch the video, you will know. I am also assuming people aren't writing code directly underneath if name main like example if __name__ == '__main__': i = 0 print("Hello") In that case, yes if name main doesn't have anything to do with global variables. A perfect if name main use is def main(): i = 0 print("Hello") if __name__ == '__main__': main() In this case, the i variable is not global. Following this convention will result in no unintentional global variables. without the main() func I think the if name main convention is incomplete. But that could be just my opinion.


sorry, I generally don't watch videos and don't intend here :/ more to the point, I now understand your position but I still think you conflate two things. the alternative to ```def main(): print()``` ```if __name__=="__main__": main()``` is NOT ```print()``` or at least, it's not the only alternative. A simpler alternative would be ```def main(): print()``` ```main()``` One doesn't need the if to avoid global variables. The only thing that if does is prevent main from running when you import the module instead of running it directly. And this means that if you never import your main file in other files (which is very common behavior), the if might as well not be there. It's still a good idea to have it (if nothing else, it is expected and might confuse someone if it's not there), but in an unrelated way to global variables, at least directly. The other common use of the if name pattern is to have unit tests inside the block, so they don't run when the module is imported. Personally I really dislike this usage and don't recommend doing it at all


pfft, I often leave demo examples under `name in main` to demonstrate how the module works. It doesn't mean, it's the main file. It means if you for whatever reason decided to execute it directly, it will do something.


The short/real answer: This is only what happens when you run an arbitrary script as your primary. So `python3 my_example.py` the `if name == "__main__"` will be true in `my_example.py` but not anything `my_example` imports. If you're building packages, though, you can include a `__main__.py` file in the package and run that entry point with `python3 -m my_package`. So there is a nicer one, but you have to know and deal with python packages to make it work. The if name trick is specifically for scripts.


As to why they have never updated the syntax, to quote [the zen of python](https://www.python.org/dev/peps/pep-0020/) >There should be one-- and preferably only one --obvious way to do it. >Although that way may not be obvious at first unless you're Dutch.


We know... but we pretend is not there... it kind of hurts to read.


why is it better to use main() in python? i have always wondered that question


Otherwise your main code would run when you simply import the file.


When you import a file in python, what actually happens is it runs that whole file once. So if you have code that is at a base level, it will be executed. So you may ask, why have code at base level if the file is intended to be imported. One thing would be using main() allows you to write per file tests, you can write simple unit and integration tests on each file’s code without doing the whole pytest routine, specially when it’s code that you can’t really write tests for but can be checked by human eyes. Another thing would be if your file is sufficiently complete enough it can also be used as it’s own individual program. You might develop a simple program, but later realize it has a lot of functions that are helpful and can be used as a library for a bigger project. If you use main(), you can import the code directly without modifying it, and thus no need to maintain to different version of the same code.




Imagine having to write 4 lines of code for main() function. ```fun main() = println("Hello World")```


Hah! I use `class main` instead and it work!


class Main: def __call__(self, *args): print('Hello World') if __name__ == '__main__': Main()()


No, as far as i know, class main will be executed just like int main.


The contents of a class are evaluated along with the class, not when the class is initialized. So you don't get any protection from importing the file and `main()` does nothing.


Compile errors are now runtime errors sucker... yeah the door is now closed for you.


And I missed the part where he breaks his neck after stumbling on a random tab character.


Is there an easy way to immediately share and format small Python code snippets too? It always seems like I have to manually adjust the tabs.


*Welcome to the pythonic experience*


1. don't use tabs, ever, your IDE should be converting them to 4 spaces for you. 2. [black](https://github.com/psf/black) will format your code consistently 3. if you use pycharm, you can right click on a piece of code and click "Create Gist" and it will share it on github gist


Click wheel to add/remove tabs to blocks of code.


> 1. ⁠don't use tabs, ever, your IDE should be converting them to 4 spaces for you. Not a python dev, why are four spaces better?




Nice I didn't know about creating Github Gists. Works for Android studio too apparently. Also tabs ftw, spaces suck!


Android Studio is basically Intellij so same functionality


Well you'd think so, but I'm for example missing "code with me" in android studio.


can't you get in in the extension store?


Not in the integrated one. There is a download on jetbrains website that claims to be compatible with android studio, I haven't yet tried it out. I find it very unsettling that it doesn't show up in the integrated one and I'm afraid of bricking something.


ok I always thought Android Studio is just modded Intellij by Google I never really did Android dev so i don't know exactly but i think you could always use Intellij with Android SDK right?


The best part is that you can google search based on your selection in the run output tab.


Yeah. I actually miss curly braces in python. A lot better imho to define scopes in code. This whole tabs / spaces magic just creates problems without really solving anything.


I once used some text formatting tool on a python file, it wasnt quite sure what it was so it tried to format it. That code never worked again. Sure it was my fault but I will always prefer brackets over white space


Random space lost when untabbing code




Yeah Python has its trade offs too. It can be cancerous in its own way




I think you are comparing apples and oranges man. At least for my needs I use for small to middle sized projects python and for "bigger" stuff Java and C#, just because I feel more comfortable having a compiler and more type safety being checked before creating an artifact. c'est tout.


It ended with a semi colon


Listen I’m a python person true and through but if those are the reasons you hate Java you probably shouldn’t be programming


We have the classic "11" - 1 in Javascript repost, "Python sucks because its weakly typed(it isn't)" repost, this post acting as if 2 of the three aren't standard and encouraged in Python, "HTML sucks because it is not Turing complete," CSS sucks because centering a div requires reading docs repost, C++ as a whole is a terrible language because I can't read the errors repost, etc. We hate all languages here not for real issues they have, but minor things that rarely affect actual usage.


To be fair, some of these do affect actual usage. - Illegable errors might be nice for the very experienced/knowledgable, but is quite the hassle for the average programmer; - weak typing can be a real pain if you forget about it, and can introduce a lot of weird bugs; and - CSS is a pain to do anything with (or maybe I just suck at CSS... I probably just suck at CSS)


I learned CSS before I learned anything else and it seriously is not that bad if you give it a little time and use flexbox.


The thing with CSS is that these jokes are older than Flexbox.


> ⁠Illegable errors might be nice for the very experienced/knowledgable, but is quite the hassle for the average programmer; That’s not really the language’s fault though. C++ is nothing but a standard, and C++ compilers get implemented based on that standard. There’s nothing in the standard that states what the error messages must be like. If you get unintelligible error messages, that’s mostly the compiler’s fault. Different compilers might produce better error messages.


Last time I was working with Javascript I had off-by-one error with my calendar returning wrong date. Turns out Javascript's Date.getUTCMonth() is zero based. Of all the things this is the one that does not make any sense to be zero based. But here we are. Tbf, Java's Calendar.MONTH has the same problem. At least C# got that right.




[Date.getUTCMonth()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMonth) I hate working with dates and timezones so much. This is like a whole discipline in itself.


Timezones are the worst. We should just all agree to use UTC+0.


The man. I'm glad someone can take on the fight, i have been fighting with javascripters saying java was too verbose, that if twotabbing and ctrl-alt-f was deemed too much, there was nothing javascript could do for them. Godspeed, man. Godspeed.


That's why semicolon was so confused and shrugged.


FYI, it's "through and through"


Well put.


Actually you define Dictionaries by using Dict = { key : value }


You can still define it as sample_dictionary = dict(key=value) instead


Or like an empty list: my_dict = {} my_dict["key"] = value


... except `Dict` is a terrible name. It's the wrong case (title case implies a class, but this is an instance) and if you were to fix that you'd be shadowing `dict` which is also a bad move. EDIT: downvoters, I'm genuinely curious as to why you think otherwise.


```dick``` is a better name imo


I don't think they are saying you should literally name it "Dict", I think they just put that there as a placeholder for the name.


I think you aren't getting downvoted because people think that `Dict` is a good name, but because you are criticizing the variable naming in a code syntax demo


I went from Python to Java and I actually prefer how Java is written. I’m glad I started with Python though, it is very easy to focus on the logic. Python is good for quick projects.


Yeah, semicolons are whatever—don't like them but they don't bother me—but every time I have to dip into python, I miss the hell out of my curly braces.


Semicolons help me feel like I just finished a proper line. Like putting a period to end a sentence.


I can respect that. I like Erlang for many reasons, but one of them legitimately is the use of a period as a statement terminator.


This is like trading in your car for a moped and then getting excited about not having to wear a seat belt.


Ok, now I can totally relate. Mopeds are fun.


this analogy is so perfect


I hate indentation being the way to define scopes {} all the way! Not like I don't indent my C# code, but for me it's just for readability, not function.


Easier to say "this loop starts here `{` and ends here `}`" and have the auto formatter indent everything according to the unique code style defined by the community, your organization, or you. Which in turn makes all code equally readable (from a formatting standpoint) and you don't have to cuss the intern again for writing fun something() { //... } When everyone else puts the bracket on the first line


It's funny how python stresses readability and standards but I find it much harder to read because of the tabs.


Who will create the mighty TypePython?


Cython is already there. Also mypy type hints.




A Python with type inference would be outstanding.




Sure, there are languages for every taste. But we also need the huge Python eco system.




what would this do differently from using type hints and a static type checker like mypy?


probably not that much, just a second solution for the same problem I guess


or PythonScript? maybe even JavaPython?


or Python++ (p++ for short)? maybe even Python# and ObjectivePython? I just want python with curly braces


`from __future__ import braces`


I'm actually thinking of learning Python. Is it good for automating tasks? Where should I start learning?


I personally use it for automating tasks, I currently have: - script to check the stock and price of a few products I want and it'll send me a link via pushbullet if the stock gets low or price changes And - script to link up my hours from Clockify (shift tracking website) and put them into a Google sheet so it's easy to invoice. They work pretty well with python and just run on Cron jobs


Python is good at everything, but great at nothing.


Python is a great place to start learning because it’s really easy to get started and the syntax is pretty simple. Just don’t stop there. Dip your toes in a few other languages and learn what their strengths and weaknesses are. Python is fun until you have to spend any significant time with it, then it loses its luster pretty quickly. Most of the people who advocate for Python on this sub have probably never used it professionally.


Let me introduce you to a Python feature: ;


Performance ……..…../´¯/)………… (\\¯\`\\ …………/….//……….. …\\\\….\\ ………../….//………… ….\\\\….\\ …../´¯/…./´¯\\………../¯ \`\\….\\¯\`\\ .././…/…./…./.|\_……\_| .\\….\\….\\…\\.\\.. (.(….(….(…./.)..)..(..(. \\….)….)….)… ) .\\…………….\\/…/….\\. ..\\/……………./ ..\\…………….. /……..\\……………..…/ ….\\…………..(…………)……………./ Backwards compatibility ……..…../´¯/)………… (\\¯\`\\ …………/….//……….. …\\\\….\\ ………../….//………… ….\\\\….\\ …../´¯/…./´¯\\………../¯ \`\\….\\¯\`\\ .././…/…./…./.|\_……\_| .\\….\\….\\…\\.\\.. (.(….(….(…./.)..)..(..(. \\….)….)….)… ) .\\…………….\\/…/….\\. ..\\/……………./ ..\\…………….. /……..\\……………..…/ ….\\…………..(…………)……………./


Add type safety to the list


Also, the garbage that is \_\_init\_\_() vs ClassName() Even if you aren't a fan of the class name being the constructor, maybe four fucking underscores in every fucking constructor is a bit much. You won't believe how many \_init\__() I have had to fix.


you don't use an ide that have auto complete?


That's just besides the point. The language should be nice enough that you don't need assistance from a IDE to write such basic stuff.


pedantic thing: dunder init is not a constructor, its a initaliser. dunder new is the real constructor, but only very rarely needed.


Haha was looking for this. Should've definitely been in the video.


Good bye type safety!


that's accurate, it's a kid


Feels this way until you try to actually write a production app in Python. Then you realize you’ve lost performance, type safety, compile time errors instead of runtime ones, a decent package manager that doesn’t have a new breaking bug with every release… oh and good luck finding a decent profiler. Python profilers are the equivalent of print line debugging. Much better to just switch to Kotlin. Works side by side with Java with all the benefits, but you don’t have to use semicolons, which Python devs seem to find so hard to type.


Don’t get me wrong, Python is my language of choice for quick and dirty side projects. Because it’s just that… quick and dirty. It’s pretty terrible for anything of any significant size. Because when you have 1M lines of code, ONE main() method that someone else wrote years ago just shouldn’t bother you too much…


ah yes, my small quick and dirty projects like youtube and dropbox


i like how people like you always have the same argument in favor of python in big projects, by citing big company names. while they do use python, it's in small non monolithic separate modules. No one in their right mind in a big company would do any big project with python.


from dropbox's tech blog: >Dropbox is a big user of Python. It’s our most widely used language both for backend services and the desktop client app (we are also heavy users of Go, TypeScript, and Rust).


I mean you probably shouldn't be writing monoliths at big companies anyway


Yeah, and Facebook, Etsy, and others use PHP, which is one of the worst languages out there. I would choose Python over PHP 1000x when starting a new project. Just because something CAN and has been used with success doesn’t mean it should. It just likely means one of the early devs liked it because that’s what they knew and now it’s too costly or not worth it to change. Also, most problems go away if you throw enough money at it. For a small company, I would never recommend Python. But it also won’t sink the company to use it. It’s fine. There’s just better options out there that will save you money in the long run in both server costs and developer time.


both suck. coincidence?


I like curly braces and semi-colons 🤷‍♂️


Me: wants to learn go, python, dart, JavaScript Jobs: Java, .net


you'll be glad because those on the top all suck


I genuinely prefer Java over python…


It depends :tm: . But I think I know what you mean.


If we all collectively refused to code in Java, they wouldn’t make us do it anymore. I’ve yet to get a good rebuttal to this idea


What’s this from?


Lock n Key


[Locke & Key](https://www.imdb.com/title/tt3007572/) (TV Series)


It looked interesting...I got through like 4 episodes before it started to feel a little too scooby-doo for my taste


How about builder classes?


which episode was this? I don't remember seeing this scene






Different tasks, different tools


If it is not a downgrade for you, you were not using Java property anyway.


Yeah all of these things are why I actually dislike Python. Those extra few characters aren't that hard to type, but IMO make reading code easier, and more clearly define where one thing ends and another begins. I'm regrettably learning Python, as it seems to be popular for reasons I don't quite follow, but I do not see myself using it as a go-to for anything at the moment. There may be some very specific feature or library that's exclusive to Python that I have yet to discover, that Might make me use it in very specific cases, but I quite like seeing a terminating brace at the end of scope of a method. Whitespace delimiters make me nauseous.


Wait till he learns a variable doesn't go out of scope after an if/for/while block



The last value of a for loop variable is still there after loop ends


Yeah that makes me sick to my stomach…


You can type hint your variable put python doesn't enforce it


Same in PHP too. Nasty stuff.


What the actual fuck.


You forgot the part where he said farewell to performance.


When I have to use python at university instead of java and it makes weird things


Come for the lack of semicolons, stay for the Jupyter notebooks. Although I wish they had braces, makes reading loops easier. But you need way less loops anyway, so I'm okay with that


thats what I felt when switching from code programming languages to low code programming


Random but where is this video from?


Well, my python compiler does allow {} or ; They are not doing anything, but if you feel like its more readable...


{} are usually recognized as dictionary/set, so if you are calling something , you will return dictionary/set with results of a function or whatever you are doing in the brackets. Semicolon isn't doing anything as far as I know Stab(as .h files in C/C++) files are mostly for documentation and don't do anything too Explicit declarations of types are optional and don't do anything other than highlighting syntax but may depend on compiler And don't let me start about ...(triple dots), it has it's own usages for displaying recursion and matrices but is mostly useless.


Semicolon is actually doing somethong. You can seperate statements. You could also use a new line for the same effect but if you like to use multiple statements in one line, you can with ; tyoe declarations are mostly used by the programmer to make code readable i guess


In all honesty I absolutely hate that python doesn't use brakets anywhere. It's like it's waiting for a single tab fatfinger to blow up your program. The good news is that it keeps all those 4 spaces instead of tabs maniacs at bay.


4 spaces is standard and [recommended by the Python Foundation](https://www.python.org/dev/peps/pep-0008/#indentation). Every big editor defaults to mapping the tab key to 4 spaces, and backspace removes 4 if done at the start of a line. Embrace spaces, mwahaha!


Why are spaces better?


Generally, one argument both for and against spaces is that they have a consistent, unchanging width. Changing the editor you use or resolution won't make them appear to be different lengths of whitespace. Good for a consistent appearance, but sometimes bad for accessibility, depending on how your eyesight may be. In Python specifically, spaces are better because the people creating and maintaining the language explicitly disallow tabs in the official style guide, with an exception being made for spaghetticode that uses tabs already, since you can't mix both in the language. Outside of situations where the language authors mandate one over the other, its probably best to stick with whatever others working on the program are using, or your editor's defaults.


Because tabs for flow control are such a great idea.


The only thing missing from this is the boy accidentally falling, screaming headlong into a huge hole with "whitespace" written on it.


You forgot the part where he gets into the absurdly shaped clown car with a 6mph top speed, and a joystick instead of a steering wheel because it’s “Pythonic” - what a joke…


you forgot the part where he switches back to Java cuz Python is absolutely shit


And then you wave goodbye to the money...


just use kotlin


switching from java to kotlin. i approve the ; is a fucking waste of time


It’s literally 1 character that’s right next to the L key… lmao


And most of the time autocomplete will do it for you.


That's the point with Kotlin, if it's a symbol that autocomplete can brainlessly fill in for you, why not have the compiler do that for you (";", public, void, final...) and have a cleaner code instead?


It's not a deal breaker or anything, but having choice to not use it is quite nice


I love those old school things than this syntax. I don't use ![img](emote|t5_2tex6|4550) just because of it's syntax


Bye to perf , hello to GIL ?


And suddenly tab comes into picture.


Nah , fuck python. Indentation is fuckery fuck.


java is almost as retarded as python


So you hate, like, every programming language, except Python? Because all programming languages I know have semi colons and curly braces, except Python. And Python does have a main function.


Anyone else just prefers brackets and semicolons or am I alone in this one?


Python for the win and beyond!


Python is nice for quick tests until you run into efficiency bottlenecks or try to use multithreading. Java is far more flexible and efficient honestly.


None of these are good things.


The video is accurate : the main character has the maturity & attitude of a python programmer.


This is missing the kid taking a skateboard to the face with Indentation Errors.


Proud feels


Same for Java to VB.net




###[View link](https://redditsave.com/info?url=/r/ProgrammerHumor/comments/r1g13n/yes/) --- [**Info**](https://np.reddit.com/user/SaveVideo/comments/jv323v/info/) | [**Feedback**](https://np.reddit.com/message/compose/?to=Kryptonh&subject=Feedback for savevideo) | [**Donate**](https://ko-fi.com/getvideo) | [**DMCA**](https://np.reddit.com/message/compose/?to=Kryptonh&subject=Content removal request for savevideo&message=https://np.reddit.com//r/ProgrammerHumor/comments/r1g13n/yes/)




Welcome significant importance of whitespace


whats the show/movie


And soon you will release that you walk about 150% slower


wait till misalignment in for loop causes you a pain


What tv show / film is this clip from? God my memory is getting bad...


Yeah python Is way easier then Java for me but dam it sucks th install on windows


huh? python.org exe installers work flawlessly...


Funnily enough these are all the parts of python that I kind of wish I had options for sometimes... The real thing is just more concise syntax in terms of printing to console and reading files, stuff like that java utils are shit


from what movie or series is this from?


He will **return;** they always do… Also I have seen this before, what is the sauce?




jython go brr


Where is this from?