Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I teach Python to learners.

It has substantial pain points, the most significant in my opinion being the semantic white space that never really ever stops being a problem.

JavaScript runs in the browser, has relatively trivial syntax, no semantic white space, C-like, a superior and more useful GUI, etc.

I see no reason to teach Python per se unless people request it.



"JavaScript [...] has relatively trivial syntax"

Really? At one point I was looking into using a linter program in my Intro-To-Programming-With-JavaScript and then realized that it didn't really catch any syntax errors because there were so few.

For example - you might call a function like this:

x = myFunction();

But what if you leave off the (), which is an easy to make, beginner/novice type mistake. Then you get this, _which is still valid JS_:

x = myFunction;

What if you leave out parameters that your function needs? What if you include extra parameters? What if the parameter types that you're expecting don't line up with ones that are provided (perhaps because you left out / added in an argument?)?

On the one hand I get it - JS is a loosely typed language so it doesn't do a lot of syntax checking at code-writing-time/"compile-time"/linting-time, but on the other hand there is a _ton_ of easy to make novice errors that are actually valid JS code.

I'm not saying that Python is a better choice for beginners, I'm just not convinced that JS's relative lack of syntax-based limits is a great choice either :)


Which linter were you using? ESLint/etc doesn't catch errors like that, you need Typescript (which can work on plain JS files as a linter).

On the other hand, your example is valid Typescript, although if you use attempt `x + 1` then Typescript will yell at you for incompatible types.

Unfortunately your example is also a problem in Python, if not worse:

    def foo() -> int:
        return 42

    # valid
    x: int = foo()

    # also valid
    x: int = foo
Why is this valid?! Well, Python doesn't actually check your type annotations, you have to choose and use a type-checker (example: mypy). There is no default type checker for Python, and invalid types are silently ignored by the interpreter.


That's interesting. The semantic white space is part of what made me fall in love with the language[1]. What kind of problems do your learners have with it?

[1] (You should be indenting to indicate your block structure anyway. A lot of beginners I've seen get their indents mixed up with the actual block structure. Not so with Python: The code runs like how it looks.)


The correct solution to this problem is an autoformatter. You should be indenting your code to match its structure, yes, but if you use Python you have to do so, whereas if you use a brace delimited language you don’t, as it’s handled for you (by the autoformatter). In both cases, your code looks right before you run it, but the editing experiences differ drastically. In Python, a simple cut/paste is nontrivial to get right and it’s difficult for editors to infer how to indent a line when you press the return key. In a brace delimited language, these problems simply don’t exist.


I don't think anything will save you if you mess up your block structure. You can mess up your block structure with indents, or you can mess it up with braces.

Personally I think it's easier to spot mess-ups with indents. Some people think braces are easier. I won't fight with those people today :-).

But I don't think randomly cut&pasting code anywhere is a good idea. If you do paste code, you really should understand what the code is doing first.


This is absolutely true. If I paste some c++ into my IDE with unbalanced braces, it can throw the whole file off.

The real key is: treat excess indentation and nesting as a code smell. Python should aim for 5 tabs deep max, imho. Anything else should be refactored into functions.


I would add that the same is true for braces in c++. Debugging the differences between }}))} and }))}} can be quite difficult , as nested scopes is never easy in any language.


I'm really starting think there are a lot of people who think "programming" is mindlessly copypasting snippets off somewhere until something works. And they don't like significant whitespace because it reduces the chances of randomly copypasted stuff doing something.


This is what is generally called a straw man logical fallacy. The issue is that something as simple as copying and pasting code (say from one file to another, both of which the programmer has written) is made excessively complex due to whitespace being significant. Call it code smell or developer smell or keyboard smell or whatever you want but this issue simply does not exist for programming languages that do not have whitespace significance.


I teach adult learners; my own experience suggests that there are multiple issues.

First, is that in no other text form, does white-space change meaning such that the text becomes "unreadable" (sure your docs may be formatted a little weirdly, but hey someone can still read it). Simple python is close enough to prose that people get confused.

Second, is that they haven't learnt to grok compiler messages - the program either works or doesn't work. Coupled with number 1, it basically means they can't /see/ any issues or fix them.


Interesting, are there other languages that they find easier to read and write?

And ... very interesting... what are the pain points when interacting with compiler/interpreter messages, in your experience? Are they introduced early on?


I haven't found one; and I hypothesize that if one were to exist it wouldn't be useful. Ironically, the GPT code generators are probably the closest - where the syntax is inexact and ambiguous.

I'm not entirely sure - but the terseness of the message and the out of the way location meant that the students... mostly ignored the errors. I think having a pedagogic IDE [1] which would /massive/ highlighting and really verbose errors may have helped; but that's entirely my speculation.

[1] Example of a pedagogic IDE which has arrows: https://i.stack.imgur.com/CwKQG.png


I agree WRT block structure, but having TA'd a Python course that "should" doesn't survive contact with a real world classroom. Students will use anything from IDLE to Notepad to PyCharm, and usually shut down completely instead of trying to work things out when the code snippet they've spliced into their program from StackOverflow fails to run because of mismatching indentation. I'm not sure why few try to understand the SyntaxError messages, but it's like they don't exist!

Part of me wants to forbid all "dumb" text editors for introductory programming courses and make everyone use an AST-based one that only allows you to create syntactically correct programs. Unfortunately there's zero chance of that happening any time soon...


Possibly you've had more students in one go than I've ever had for all the languages I've done put together then. That said:

Here's a weird thing that seems to work (especially while learning): Instead of copy-pasting code, type it into your program by hand. For some reason this helps a lot when trying to understand or debug the code that you are entering.

This works equally for those of us who started learning using BASIC on 8-bitters, all the way to Python, Java, or odd things like Siemens SCL.

Wrt editors: the times I've taught people, I actually went completely the other way: requiring the first few programs to be written in notepad or nano (depending on OS) . This tends to take the magic out of what the IDE is doing, and makes everything after it much easier.

Both of the above would seem to be relatively time-consuming. But oddly enough in practice they can save more time than they consume.


This is one of the key parts when starting to learn programming. Just typing out everything manually really helps you see the small details that are important when writing code that can get lost when copying from elsewhere. Courses like Learn Python the Hard Way focus on this method and I think it's the best way to go for absolute beginners.


Absolutely, I find this approach gets the right mental gears turning as well. The problem comes up most often with take-home assignments though, where students are more likely to copy-and-paste a couple lines from somewhere because you haven't given them a full program. If anything, an IDE might be better because it'll give more localized feedback and people are more likely to react to the red squiggles :)


I’m a bit taken aback by this message. My students have never copied and pasted a single line of code aside from their own...

I also don’t give homework. If you want to learn on your own, you can, but homework is a massive crutch that I don’t think benefits most people.


Whenever I hear a story like this, I always ask:

Have you taught a similar crowd any other language and gotten a different experience?

Because what you describe sounds like the students in my introductory programming class, which was in C++. Sure, they didn't have whitespace issues, but did demonstrate a similar lack in rigor, and giving up easily.


No, though I have plenty of anecdotes from friends who have. I agree that these apply regardless of language. Whitespace errors are arguably some of the more insidious syntax errors though, since most editors will not differentiate between spaces and tabs (e.g. vim's set list) and to the beginner programmer it doesn't feel like the number of spaces should matter (I'm indenting my blocks, why do you care how much?)


> I'm indenting my blocks, why do you care how much?

The equivalent in an introductory C/C++ class:

"I put a newline, why do you care if I put a semicolon?"

At some point, students have to accept the quirks of any language's syntax. It's OK to have an opinion and hate it, but whitespace complaints are mostly a preference issue.

(Every time I switch from Python to a language requiring semicolons, it always feels like I'm hitting endless speed bumps.)

While Python may not be a beginner language, nor is Java/C/C++, in my opinion - and for people completely new to programming, those have a steeper learning curve than Python (the for loops are just hideous). These were the standard introductory languages in college before Python took over. I'm sure better teaching languages exist, and I'm also sure JS is not one of them ;-)


Don't get me wrong, Python is head and shoulders above Java/C# or C/C++ as a teaching language. The complaint is that, as the educator, lab/tutorial time is being wasted on trivial syntax issues that would be non-existent given a more lenient parser or better tooling (preferably the latter).


I’m not sure that statement is accurate, I could see an argument being made for C being a really good learning language.


If your goal is low level programming, yes.

If your goal is understanding data structures, algorithms, etc, then C is hideous. Explaining function prototypes, include headers, very unfriendly I/O, and I already mentioned the horrible syntax for for loops.

There's a reason most of the data structures/algorithms were in a second course at my university: It's because it took most of one semester for students to get a handle on the very basics of C syntax.


It would be the best possible learning language, if your next language was going to be assembly.


Is that a crack about complexity? C doesn’t have very many features.


I’m saying that the C machine model would be an ideal introduction to pointers and registers and bit manipulation, and you could compare a C program with its compiled disassembly. Later you could get into in-line assembly and even processor intrinsics.


Alright, I see.

Another good candidate is golang.

I’m going to think on that one a bit more.


I've taught Python for beginners for many years. I've had zero problems with the significant whitespace.

JavaScript syntax is outright bizarre compared to Python. Care to share your slides teaching the semicolon rules, four or so different scopings, the damn "new", type coercions and so on to learners?

Javascript has mostly nicer semantics, but buried deep in ugly pile of mess. And CPython is a disgrace.


My “problems” with semantic white space are more along the lines of “oh, well, this is clearly unintuitive or is creating small errors”. It’s also one of the most persistent thing that learners will forget, even the good ones, when writing their own code. Defining a class method, and then indenting back to the original scope has some degree of cognitive overhead that simply enclosing things in typical c-like lexicon, i.e. with the interpreter noting brackets and not white space, doesn’t have.

As for teaching JavaScript’s pain points... that’s not really how I operate. I’d rather they know the general rules and come across edge-cases when they’re in a position to solve them, rather than overload them with information. Automatic semi-colon insertion is powerful enough to get you through several large-scale projects, so there’s essentially no point to discuss it prematurely as anything but a curiosity, “this could be a gotcha, so keep your code clean”.

Finally, comparing the error linters in VSC for Python versus javascript, especially if you //@ts-check... I think JavaScript actually does a better job.


Maybe people perceive code/indentation differently. For me there's nothing unintuitive about semantic whitespace. I don't really even see braces or other block delimiters when reading a language with those (although lisps' parenthesis mess is just too in your face...), and more easily tripped by mismatching indentation and delimiters. Maybe some people have harder time seeing the relative indentation? Does an editor showing the levels with e.g. vertical lines help with this?

I have hard time understanding how changing the indent has somehow more overhead. Even with dead-simple automation where the current indentation level is kept for a new line the blocking is literally controlled with just backspace, tab and enter (space indenters and their enablers shall rot in hell).

Braces are also awkward to type with many keyboard layouts. Once you get used to it it's not much of a problem, but for beginners in can be an annoyance distracting from the actual programming.

Javascript quirks are so prevalent that you're bound to encounter them even in the very beginning. E.g. in comparison operators or accidentally assigning to global scope.

I don't use linters and haven't really felt the need. Heavy use of linters tends to be caused by bad language design and/or obsessing over pointless cosmetics.


I think that people do indeed have a harder time perceiving the physical structure of the code, especially if they’re not spatially oriented as thinkers, e.g. myself, I’m a Linguistics person first and foremost, not very good at spatial reasoning.

You should really consider using linters as a teaching aid. They help a lot, and would indeed catch the problem you noted about js.


Among bad ideas in Python, I think using semantic white space is the worst. Of course, you can always use an IDE to simplify your life, but it is still a terrible decision.


I consider the semantic whitespace to be one of the best features of Python, especially for beginners. It forces them to indent their code properly, something few other languages do.


JS is so much worse for beginners than Python. The way there's like 3 or 4 different ways to do the same thing, with developers usually picking the one that makes them look the most clever, is horrible for beginners. The scoping rules and behaviour of this are bizarre.

If your beginners prefer C like syntax then I doubt they are really beginners at all.


If you’re instructing people, having more options becomes a positive, not a negative.

Incidentally, Ruby has a similar problem for self-learners.


I could never teach JavaScript to beginners. There are a million ways to do everything, there are a million platforms each with their own compatibility quirks, almost everything is asynchronous, every framework tries to reinventing the language, and almost every project ends up with a massive, complex dependency tree.

Python's whitespace rules are a minor nuisance to some, but at least there is consensus among Python devs on how to do something as fundamental as iterating over a list.

I write JavaScript all the time. It has improved a lot over the last decade. But I could never teach it to a beginner.

Don't get me wrong, though. I wouldn't teach Python to a beginner either.


Python is absolutely not beginner friendly, but JS is just worse when you consider its who-knows-what-is-in-there nodejs and npm and twenty different ways to build and treeshaking or whatever. If I have to pick one, it has to be python unless I do web frontend.


I see no reason to teach Python per se unless people request it.

As someone not really familiar with python besides using it instead of one off bash scripts, I have the same feeling about using it. When is python to appropriate language to pick? Not high performance, not safe, does not run in the browser, not embed friendly, no unique features. There are more mature and bigger ecosystem out there with better tooling and there is the whole python 2 vs python 3 thing.

Yet I see so many python positions advertised, that I consider picking it up.


When is python to appropriate language to pick?

For almost every science or engineering domain, python has some of the best in class libraries available (either native or as bindings to the standard C libraries everybody uses). It is more likely than not a plug in or scripting language for the engineering desktop application you use. It will let you do everything from interactive data analysis to web development, to scripting and devops, to cutting edge ML research in the same language using mature and battle tested tools. This is extra nice if you are combining many different domains, like doing Machine Learning and Computer Vision on GIS data and presenting the results on an interactive web site.

Especially if you're ambition in life isn't to be a professional programmer, but rather a professional that uses programming to do his job, then learning just one language is very enticing and python is probably the language that is most likely do have everything you need to get the job done, no matter what that job might be.


If all you are focused on is web development, then no - python is likely not the language for you. Especially if you want to do frontend. The reason that python is popular isn't because it has particularly unique features. It's that it has a huge swathe of useful libraries that no other language even comes close to.

Numpy, scipy, matplotlib, flask, django, tensorflow, ... all the way down to tiny packages like emcee makes it an extremely compelling ecosystem to develop software in.


The argument Python fans will give is the ecosystem: it has many mature libraries.

Shell scripting, e.g. dev ops? Ruby for me, Perl for complex regular expressions.

Web development? This depends.

High performance environment? Golang, C.

Basically, the care where Python is called for is the scenario where it offers a library you absolutely need, not anywhere it’s definitely the best language for the job, because it rarely is.


Don't consider picking it up if you don't like it. Stick to other languages that have "more mature and bigger ecosystems" and ones with "better tooling", you'll enjoy them more.


Indeed, I will not start a python side project, but at the end of the day a job is not about enjoyment but a paycheck.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: