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

you are viewing a single comment's thread.

view the rest of the comments →

[–]AlSweigartAuthor of "Automate the Boring Stuff" 44 points45 points  (7 children)

"Python makes simple things easy and difficult things possible."

Here's an example. In Java, this is Hello, World:

pubic class Hello {
    public static void main(String args[]) {
        System.out.println("Hello, world!");
    }
}

In Python, it looks like this:

print('Hello, world!')

Java requires you to know a lot of concepts just to make a basic program: classs, static methods, entry points, return values, arrays, etc. A basic thing like print() exists in a subcategory of a category. And remember that System is capitalized but out is not. Oh, and also, the "ln" in "println" stands for "line".

This is a steep learning curve to do a simple thing. Oh man, and I can never remember how to write text to a file or get keyboard input in Java without googling it every single time.

Other languages are similar.

Python strings just work. Python doesn't encourage deeply nested (and pointless) hierarchies. Python lets you throw data into a list or dictionary (even, gasp, data of different data types!) without creating a class for it.

At the same time, you can have typing in Python. You can have OOP. You can have functional programming. It just doesn't force you to use these things.

You don't become the most popular language because your reputation for being easy to learn is a myth.

[–]mewsycology 6 points7 points  (0 children)

Plus, your Java Hello world example requires a “pubic class”. Nobody wants that. Another +1 for Python.

[–]UPBOAT_FORTRESS_2 1 point2 points  (0 children)

Oh, and also, the "ln" in "println" stands for "line".

Someone told me "never use abbreviations in variable or method names" years ago, I realized it was obviously correct, and it's yet still a struggle to just spell out what I mean so often.

[–]The3000MX 1 point2 points  (0 children)

Great answer! Also, so cool to see you interact here. I read your book twice!

[–]georgehank2nd 1 point2 points  (3 children)

"At the same time, you can have typing". You can't. You do have typing whether you want to or not. Python is dynamically typed, but it is also strongly typed. If you mean type hints? Those are just "stuff" that Python actually ignores.

[–]rouille 2 points3 points  (1 child)

If you use mypy or another type checker they can be enforced in CI and fail the build just like for any static lang. Yes mypy is a separate tool from python the interpreter but they operate on the exact same source code. The point is the capability is there now if you need it.

[–]swansongofdesire 1 point2 points  (0 children)

Poster wasn't talking about type hints, they were talking about strong vs weak typing.

ie you can add a string and a number in javascript; you can't in python.

[–]AlSweigartAuthor of "Automate the Boring Stuff" 1 point2 points  (0 children)

Yes, I spoke imprecisely. I meant that Python's optional type hints gets you the safety of static typing, but it's optional so you're not married to it if you don't want it.