Live data from Hacker News

Why People Should Learn Python

iluxonchik.github.io

241–250 of 329 posts

Re: Why People Should Learn Python

#241
post #2

Now that I have a chance to ask: I've always found the def __init__ method with 4 (!) underscores one of the ugliest things I've seen in a programming language. Don't get me wrong: I like Python and know it's truly good, but __why__??

Call me ignorant, but I agree. Having something like __init__ and __new__ is very confusing for a beginner, along with stuff like "__init__.py". It doesn't stop there: Take something like __str__ and __repr__ combined with str(), repr(), vars(), dir(), print(), pprint.pprint()... I have no idea how anyone ever thought it was a good idea to have that many ways to output the content of a variable. Even after all the ti…

The dunder functions are there to provide an interface to global functions and operators.

If you want to affect how str(x) behaves, you override x's __str__() method. Operators behave this way too: for example, if you want to overload the == operator for a class, you override __eq__() in that class (for any Java developers reading: Python == works like Java equals(); the Python version of Java == is the is operator, which cannot be overloaded). Yes, that means x == y is just syntactic sugar for x.__eq__(y).

The dunders are there so you have the freedom to name your methods what you want without having to worry that you'll accidentally clobber a method that affects a global or an operator, as most people won't just up and decide to both begin and end a method's name with __.

Re: Why People Should Learn Python

#242
post #209
post #160

Earlier quoted context omitted.

Yes I would. Requiring a character set outside of ASCII is what I'd call a high-risk design decision, that could easily become a misfeature of a language. Windows "smart quotes" are bad enough and that's not even a programming language. This is why people invented J as an alternative to APL.

Would you say it's "hard to copy and paste Unicode"?

Most systems support UTF-8, so most of the problems have been solved by now. There's still a lot of scope for malicious or very surprising unicode; invisible characters or modifiers, font problems, RTL/LTR, characters which have different code points but cannot necessarily be visually distinguished ("ı = 1" etc), good old Zalgo, and so on.

Re: Why People Should Learn Python

#243
post #230

Earlier quoted context omitted.

Around 2001 I felt jaded with the industry and determined to do whatever was expedient to earn money. That meant using PHP, because that was purportedly the place to be at the time. I have never felt so uninspired by a language. My overwhelming feeling from the get-go was that it was a collection of libraries, which would be fine -- but why create a new language? PHP has the rare distinction among languages of not co…

> I have never felt so uninspired by a language. I agree with this sentiment very strongly. I understand that there's a lot of hate, flamebait, etc etc about the language, with which from my own experience I agree with or disagree with in fairly equal parts. At this stage, I have written more large web projects in PHP than any other language (for varying reasons). I don't proselytize on why it is (or is not) a good l…

"while working with PHP, I tend to feel vaguely annoyed"

Exactly! I was never satisfied with my PHP code, as there does not seem to be a better and worse answer in many cases.

For the record I did not mean to assert that PHP has become secure, I meant that I presumed it had. Some years ago it was a laughingstock on Bugtraq.

Thanks for the feedback!

Re: Why People Should Learn Python

#244
post #2

Now that I have a chance to ask: I've always found the def __init__ method with 4 (!) underscores one of the ugliest things I've seen in a programming language. Don't get me wrong: I like Python and know it's truly good, but __why__??

The second annoyance is that you need to write __init__ methods quite often.

Correct me if I'm wrong, but there doesn't seem to be built-in support in Python for having attributes initialized by the the constructor.

For example in Perl 6, I can write

    class Point {
        has $.x;
        has $.y;
    }
... and I get a constructor Pair.new(x => 1, y => 42) for free, no need to write custom initializers.

Re: Why People Should Learn Python

#245

I just wanted to point out a bit of syntax from the article. I'm a huge fan of compact variable declaration if statements. The code from the article: if name in names: names[name] += 1 else: names[name] = 1 That can actually be written as just one neat, readable line: names[name] = names[name] + 1 if name in names else 1 It may not be as readable to some who are used to spelling it out as an if/else block, but I real…

NO. That is not more readable, and is warned against in most style guides and code-quality books.

In the original, at a glance I know exactly what is going on.

In your version, I have to read the whole sentence carefully to notice that it's even a conditional and not a normal assignment, and then I have to mentally unpack it to understand the logic that you're trying to implement. If/else should never be a one-liner.

Good code is boring code :)

Re: Why People Should Learn Python

#246

Is it just my feeling or are there languages which are preferred on HN? Indicators for languages which are liked by the HN community: - Positive stories get many upvotes and are instantly at the top of HN - Most comments are positive - Frequent coverage on HN about the language Indicators for languages which are not liked by the HN community: - Rants get many upvotes and are instantly at the top of HN - Most comments…

Ordering languages and frameworks by amount of 'love' (edited with small adjustments): ***** Python, Rust, Lisp ****' Go, Swift, C, PostgreSQL **** Elm, Elixir, Typescript, Haskell, OCaml, JS-ES6, Kotlin, Crystal ***' Scala, Lua, Clojure, Erlang *** C#/.NET, Java, C++, Ruby, JS-ES5, MySQL ** Node JS, RoR, Meteor, MongoDB * PHP, VBasic, Cobol, Coffeescript

If PG gets 4 stars, I'd put MySQL at 2 or 3 based on all the comments that show up in MySQL stories: "Why didn't they use feature X in PG?" "MySQL kicked my dog and cheated with my significant other", etc.

Re: Why People Should Learn Python

#247
post #38

Earlier quoted context omitted.

What I find interesting is that we are so quick to follow new trends.

While I generally agree with you, I'm not sure Python is a new trend.

I had an opportunity to learn Python around 1996, and I passed. When I came across it again in 2003 I tried it, then kicked myself for not jumping on the bandwagon earlier.

Re: Why People Should Learn Python

#249

Earlier quoted context omitted.

Wordpress is horrible. Never going to touch that again (Senior PHP Dev myself) or anything else like it (Magento, Drupal,...). And yes there is a lot of horrible PHP code out there, writting by bad developers. I guess newer or not as accessible languages don't have as many bad devs as PHP/JS. But if you have good devs, I prefer a good PHP codebase to any other language that I have come across (I tried a lot of them).

Could you elaborate a bit on what you prefer about it? I've heard this from a few people and would be curious to hear it fleshed out a bit.

It has most of the OOP things that I want in a language (interfaces for one, looking at you python), few things still missing but hopefully coming soon (generics, nullable typehints). And it has sane nulls in my opinion, compared to Java at least.

In the end good PHP code ends up looking like good Java code I think. But you don't have to worry about everything being nullable.

But then horrible PHP code is something else... Luckily I don't really have to touch that very often.

Re: Why People Should Learn Python

#250
post #198

Python is so easy to write, use and read, I would not understand how a programmer would not know it already. It literally has everything you want in a language. Granted, it's not on-the-metal fast, and it still has some gimmicks, like variables behaving like pointers or references (which can be a little awkward), but still, python is the language of the decade.

Ugh. I tell you, I keep trying to pick it up because I hear so much about it. However, when I code in it I feel completely uninspired. I can only get so far into a book or tutorial before my eyes glaze over and I'm thinking about something else.

I think when I code, I want to own the machine, not just skate on the surface. Python doesn't even crank my engine the way BASIC did years ago.

I also think part of my problem is it doesn't solve any needs right now.

Post reply on HN