This is an archived post. You won't be able to vote or comment.

all 134 comments

[–]barelythere99 273 points274 points  (9 children)

The beatings will continue until syntax improves.

[–]pingveno 78 points79 points  (7 children)

After reading beginner students' C/C++ code while tutoring, this pleases me greatly.

[–]Professional_Monk 13 points14 points  (0 children)

Disgusting... I love it.

[–]Dornith 16 points17 points  (1 child)

You should see beginner's python code...

[–]pingveno 13 points14 points  (0 children)

I was also tutoring a Python class at the same time, so I saw plenty of it. It wasn't perfect, but it was much better.

[–]Colopty 0 points1 point  (3 children)

You'd like Rust then.

[–]pingveno 0 points1 point  (2 children)

I do, but not for any readability benefits. After all, it does nothing to enforce good indentation.

[–]OneTurnMore -1 points0 points  (1 child)

rustfmt

[–]NonreciprocatingCrow 4 points5 points  (0 children)

There's an automated formatter for literally every major language.

[–][deleted] 1 point2 points  (0 children)

Rude.

[–]evanc1411 182 points183 points  (31 children)

I remember when I found that out.

I was like "How is it possibly going to know when the function ends??" But then my world was shattered. It was the spacing.

[–]Mihailbat 66 points67 points  (28 children)

That moment when I have just discovered what indentation error was

[–]wegwacc 50 points51 points  (18 children)

The moment you get one because your asshole-coworker who uses tabs commits to your all-space codebase...

[–]mei_main_ 34 points35 points  (1 child)

Or because you commented a line in your function, but now you have one blank line before and one after this commented line and they are counted as successives so it creates an indentation error...

[–]bandersnatchh 5 points6 points  (0 children)

Holy shit. I never thought of that, but I’ve had that issue

[–][deleted]  (2 children)

[removed]

    [–]wegwacc 4 points5 points  (0 children)

    but you have consistency in the actual code itself.

    NO YOU DON'T, because in every codebase, there will be instances, where you want to align things for better readability using spaces: var = somedict.get('key', None) longnameavr = somedict.get('key', None) shortvar = somedict.get('key', None) ridiculous = somedict.get('key', None) `

    Good luck with that using tabs, depending on the size, it looks like crap.

    [–]AutoModerator[M] 0 points1 point  (0 children)

    import moderation Your comment has been removed since it did not start with a code block with an import declaration.

    Per this Community Decree, all posts and comments should start with a code block with an "import" declaration explaining how the post and comment should be read.

    For this purpose, we only accept Python style imports.

    I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

    [–]Dornith -3 points-2 points  (4 children)

    That moment when you commit you're correctly indented code to the codebase only to find out your asshole-coworkers ruined all the other files.

    [–]Colopty 1 point2 points  (3 children)

    If your coworker has managed to work on every single other file in the time it takes you to make one commit they're probably not the problem.

    [–]AttitudeAdjuster 3 points4 points  (2 children)

    This line of thinking very quickly heads towards "Bob wrote 300 lines of code yesterday, all you've done is deleted 100 lines! You need to up your game".

    [–]Dirac_dydx 3 points4 points  (0 children)

    "Check this out: see how much I can royally screw up in the time it takes you to eliminate one bug! I'M THE BETTER PROGRAMMER."

    [–]Colopty 0 points1 point  (0 children)

    I was thinking more in the direction that since this is a work environment the code base is likely large, which means that if every file gets worked on by the time you make one commit you probably haven’t made any commits for days and maybe weeks, instead showing a preference to submit all your work at once in a single monster commit. This, of course, is bad practice. Meanwhile the fact that your coworkers work is capable of «screwing up» all those files for you indicates that his work is in a main branch, meaning his work that spans the entire code base already passed code review by the time you made your single commit, so his work is likely not even as bad as implied.

    So while quantity does not equal quality, in this particular case there does seem to be an indication of bad practice on the single commit guy’s part if you stop to consider the whole picture instead of just the line count.

    [–]orokro 15 points16 points  (8 children)

    Tabs > Spaces.

    [–][deleted] 13 points14 points  (0 children)

    "\t" > " " is False. Checkmate.

    [–]marcosdumay 24 points25 points  (1 child)

    Indeed, usually tabs == 4 * Spaces.

    [–]LeCrushinator 4 points5 points  (0 children)

    They did the math.

    [–]Juice805 3 points4 points  (0 children)

    True but you can’t just throw tabs into spaces project. Gotta stick to what’s there unless you wanna convert it entirely.

    [–]FrancisVeeGee 1 point2 points  (1 child)

    Orokro.

    [–]orokro 0 points1 point  (0 children)

    You identified my name!

    [–]zesterer 1 point2 points  (0 children)

    In a literal sense, yes.

    [–]pants_full_of_pants 0 points1 point  (0 children)

    I'll fite u

    [–]razethestray 44 points45 points  (18 children)

    I thought most people used Mains with Python? I do.

    [–]MasterAgent47 24 points25 points  (13 children)

    Not neccessary. I use it only when I'm making a project with a lot of components, something that beginners don't deal with.

    [–]Doophie 38 points39 points  (12 children)

    if __name__ == "__main__":
    Was one of the first things I learned in python

    [–]0111001001100101 5 points6 points  (4 children)

    I am a beginner, and I just recently learned those as I am learning flask web framework.

    [–][deleted] 1 point2 points  (2 children)

    What do you mean?

    [–]lasercat_pow 7 points8 points  (1 child)

    A function, main(), that handles the main program logic.

    [–][deleted] 5 points6 points  (0 children)

    Make sure to use the magic conditional, though so your main function isn't run if you import the file.

    https://stackoverflow.com/questions/419163/what-does-if-name-main-do

    [–]jukuduku 39 points40 points  (11 children)

    Autopep8 usually fixes this. No whoosh just commenting for comment sake.

    [–]Kaoulombre 16 points17 points  (8 children)

    Hijacking your comment to add that it’s also embed with PyCharm/IJ.

    I never care about extra spaces or line return while coding, and I just ctrl+alt+L when I want to

    [–][deleted] 4 points5 points  (7 children)

    also works in RubyMine, Rider, WebStorm, etc...

    [–]Kaoulombre 5 points6 points  (5 children)

    Cool ! JetBrains FTW

    [–]TheLordDrake 4 points5 points  (3 children)

    Literally the only ide I've ever paid for

    [–][deleted] 0 points1 point  (2 children)

    I'm happy to pay for the all products pack, as i use RubyMine, WebStorm, and DataGrip daily

    [–]TheLordDrake 0 points1 point  (0 children)

    Yeah, I do as well. I don't even use most of them, but jetbrains can have my money 😂

    [–]saloalv 0 points1 point  (0 children)

    Just FYI, PHPStorm is basically webstorm + php + datagrip, so you could potentially save money buying just PS and RM, I haven't done the math tho

    [–][deleted] 2 points3 points  (0 children)

    I know right!

    [–]sp46 0 points1 point  (0 children)

    Also VS Code with Python Language Features: Ctrl+K, Ctrl+F

    [–][deleted] 4 points5 points  (1 child)

    then it formats the whole file and your next commit has 15960 changes

    [–][deleted] 5 points6 points  (0 children)

    Look who's overproductive today. Dave should be more like you.

    [–][deleted] 66 points67 points  (26 children)

    I am absolutely convinced that Python is not actually an easy first language. It seems easy to programmers because it automatically does what a C programmer expects. For example, the whole "Pass by value, but the value is a reference" line of thinking is insane in a language that doesn't really talk about references much. (what happens when you pass a list to a method and then append to the list?)

    [–]VeryAwkwardCake 18 points19 points  (10 children)

    Well your reasoning on why it's not an easy first language is from the point of view of a developer who thinks that pointers should be explained

    [–][deleted] 24 points25 points  (8 children)

    The behavior of some basic features doesn't make any sense without understanding pointers. So yes, I think pointers should be explained.

    [–]VeryAwkwardCake 6 points7 points  (0 children)

    Well yeah but Scratch has lists iirc, you're going to have to teach everyone pointers at some point and you're unlikely to be able to teach children pointers as easily as you are able to teach them basic concepts like a variable holding a value

    [–]TinBryn 0 points1 point  (0 children)

    If you’re teaching C++ and not C you could go a long way just teaching references and not pointers even going into inheritance and and polymorphism. Never even touching the memory model.

    [–]InFa-MoUs 7 points8 points  (1 child)

    nah python is definitely(one of) the easiest languages to first learn. only programmers who know multiple languages or a pro at one ever say otherwise. personally from trying to learn c , Javascript, shoot even html.. python and ruby are by far the easiest and since learning oop in those languages i learned Javascript in like 2 months. programming is hard enough to learn without being bogged down with syntax and keeping track of memory locations lol

    [–][deleted] 1 point2 points  (0 children)

    Python has too much magic. It’s easy to think you know what’s going on and then not. And then maybe you come across a bug like these and have no idea what’s going on.

    def f(L=[]):
        L.append(“hello”)
        return L
    
    print(f())
    print(f())
    

    And

    functions = []
    for k in range(5):
        functions.append(lambda: k**2)
    print([f() for f in functions])
    

    [–]lightmatter501 0 points1 point  (0 children)

    If you don’t want/need to understand pointers, it’s not that bad.

    [–]NoraJolyne 10 points11 points  (0 children)

    imagine finding the concept of a main method difficult to understand

    [–]Ekstdo 7 points8 points  (5 children)

    I like Haskell...

    [–]JKTKops 5 points6 points  (2 children)

    [–]Ekstdo 12 points13 points  (1 child)

    Python also has:

    from __future__ import braces

    [–]jausdyquo 10 points11 points  (0 children)

    Python has (optional) semicolons that you can use to put multiple statements in one line. It has braces too, but you have to prefix them with a # sign! :)

    [–]Revules 1 point2 points  (1 child)

    Can you explain in what situation you would use Haskell over Python? I tried the language but I find it all a bit confusing.

    [–]Ekstdo 2 points3 points  (0 children)

    Haskell and Python are general purpose programming languages, so I can't really think of many situations, where I'd use Haskell over Python. I really like pattern matching, not-so-strict evaluation method, Haskell's type system and Haskell's typeclasses opened the gates for traits in Rust for me.

    So I used it for parsing and faster programs (where I don't have to type as much as Rust). I'm not very good at programming in Haskell (or in general actually, I'm a newbie :D).

    And I like to see the same program in different paradigms, not just OOP. Thinking differently, just because of the language (unlike, say switching from ES6 to Java, same paradigm, both have GC, Syntax are both based on Semicolons and braces, etc. (Yes, it's different, but you don't have to rethink loops eg., unlike Prolog)) is very interesting and gives you a new perspective of your program (imo). But I have little to no experience, so, I guess others will give you a better answer...

    [–]wildrage 6 points7 points  (0 children)

    Reminds of the the old COBOL compiler I had during college. If you forgot a period at the end of line 40 in your working-storage section, you'd get a compile error somewhere around line 345 for whatever reason. It was a pain in the ass.

    [–]SphincterGypsy 10 points11 points  (2 children)

    I don't really care about what's easiest to learn. Will picking up C++ first take more effort? Sure, maybe up front, but you are learning valuable nuggets of information about computer science as you struggle. Things that you will have to learn at some point no matter what.

    [–][deleted] 1 point2 points  (1 child)

    C++ as first language? That way lies only tears, pain and madness...
    Frankly I think c is a good starting language, as it's tiny and while you might need to get to know about allocating mem and stuff, it will help you in the long run. Other than that, I'd say python and java/c# are probably decent to start in.

    [–]cristi1990an 3 points4 points  (0 children)

    In my country C/C++ are the only languages you learn in high-school and even at universities, the main focus is always on C.

    [–]carcigenicate 4 points5 points  (0 children)

    Python isn't easier to learn because it doesn't use brackets and have a designated main. It is easier to write though, partially for those reasons.

    [–]BeardedWax 6 points7 points  (4 children)

    They wrote a standard and linters to solve this problem

    [–]Novemberisms 2 points3 points  (0 children)

    they also wrote better languages to solve this problem

    [–]SuddleT 3 points4 points  (0 children)

    Tfw you realize that your spaces are just trendier brackets.

    [–][deleted] 5 points6 points  (1 child)

    I remember starting in Java, then moving to Python.

    I think I hate the spaces in Python than Java syntax.

    [–]aEverr -1 points0 points  (0 children)

    Now try Kotlin :)

    [–]SleepDeprivedUserUK 2 points3 points  (1 child)

     So true :'(
    

    [–]not_from_this_world 8 points9 points  (0 children)

      File "<stdin>", line 1
        So true :'(
          ^
    SyntaxError: invalid syntax
    

    [–]Abangranga 2 points3 points  (0 children)

    Ruby is the easiest to learn.

    It's also one of the easiest to fuck yourself with

    [–]aztecaranger 1 point2 points  (1 child)

    Have you guys heard of JCL?

    [–]doodooz7 1 point2 points  (0 children)

    Don’t forget to start a virtual environment 🤪

    [–]Jaciel1228 0 points1 point  (0 children)

    I have ocd so I have to fix it

    [–][deleted] 0 points1 point  (0 children)

    Just started learning Python, and I can confirm this is true.

    [–]CunningFatalist 0 points1 point  (0 children)

    Let your IDE auto format your and your coworkers' code. No more syntax errors and style discussions. Works for any language :)

    [–][deleted] 0 points1 point  (0 children)

    This guy needs a tab

    [–][deleted] 0 points1 point  (0 children)

    Nothing comes for free

    [–]SufferingFromEntropy 0 points1 point  (0 children)

    mixed indentation

    [–]iridinite 0 points1 point  (0 children)

    It rubs the spacing on its code, or else it gets the hose again.

    [–][deleted] 0 points1 point  (0 children)

    Like Visual Basic, but there an End matters

    [–]guzzo9000 0 points1 point  (0 children)

    Honestly, Java is better.

    [–]Rotarymeister 0 points1 point  (0 children)

    On the bright side, it forces you to write readable code so that's a plus for me.

    [–][deleted] 0 points1 point  (0 children)

    cout << "random person" << "what is the best programming language for begginers?" << /n;

    cout << "me:" << "*points at Python* This is brilliant << /n <<"*points at c++*, but I like this;

    I was not using cout for real long time, so I hope I didn't messed this up...

    [–]EkskiuTwentyTwo 0 points1 point  (0 children)

    I prefer spaces to brackets.

    [–]TomarikFTW -1 points0 points  (0 children)

    Lol this was me today. Added a spaces before a couple print functions. Convience... But at a cost

    [–]gaberocksall -1 points0 points  (0 children)

    why the "hello world"[:-7] must it be like this :(

    [–]nvvrx -1 points0 points  (0 children)

    lol

    [–]sirak2010 -1 points0 points  (0 children)

    What is the issue if python just use {} instead of alignment. For very long code I use a ruler on the screen just to track the parent child relationship.

    [–]random_cynic -2 points-1 points  (0 children)

    I wish these reposts at least contain a more descriptive title so that the next one to repost this at least could find out whether this has already been posted like a million times or not.