Live data from Hacker News

Why People Should Learn Python

iluxonchik.github.io

291–300 of 329 posts

Re: Why People Should Learn Python

#291
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.

Nothing built in, and generally not recommended, but you can do it! If you want to be really flexible and just allow any attribute, you can do this:

    class Foo:
      def __init__(self, *args, **kwargs):
        self.__dict__.update(**kwargs)
And it will automatically assign any keyword arguments you use as attributes to the object. For example `foo = Foo(name='Bob', age=99)`

If you still want to keep a strict list of allowed attributes, you can define them as parameters, and use a shortcut to assign all local variables to attributes.

    class Foo:
      def __init__(self, name, age):
        self.__dict__.update(locals())
        del self.self
So `foo = Foo(name='Bob', age=99)` will still work as will `foo = Foo('Bob', 99)`. But `foo = Foo('Bob', 99, True)` will throw an error, as will `foo = Foo(name='Bob', age=99, likes_cake=True)`. You can add kwargs back to the parameter list if you want to allow assigning any attribute.

This isn't recommended though. So for all practical purposes, Python does require a bit of boilerplate in the constructor.

Edit: Realized a cleaner way to do the second example.

Re: Why People Should Learn Python

#292

Earlier quoted context omitted.

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

Add: * * * * * WASM Dare to question the pragmatics of diverging web dev practices into a whole new realm of complexity and drown in downvotes - and a litany of people being downright personally insulting/condescending. This is sort of a corollary to JS being * (I think you ranked ES6 too high) and I've been inured to people hating/ranting against JS to a point - but even I was shocked by the personal rancor that ooz…

I agree, it would be more reasonable to rank JS-ES6 and Kotlin with 3.5* instead of 4. And Go with 4* instead of 4.5*.

Re: Why People Should Learn Python

#293

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…

That's close to my perception. If you gave one of Python's stars to Ruby and RoR, gave two of Go's to Elixir and created an entry for Lisp with six stars, it would be pretty much exactly what I'd estimated from this site.

Re: Why People Should Learn Python

#294
post #20

Earlier quoted context omitted.

I've been programming for 20 years and don't know any of those languages.

That's surprising! So which are the languages you use (I'd expect to not know any of them :-))

C++, C#, Javascript and now Swift.

I know many others who have been programming their whole lives in one or two programming languages. Once you get good at something and are well compensated, there may not be enough motivation to learn new languages. Specially when you have kids and other hobbies.

Re: Why People Should Learn Python

#295
post #110
post #31

Earlier quoted context omitted.

But you writing this as a bad thing? It's normal for a community to pick tools/solutions that are preferable. A lot of HN users are for example startup owners/creators so it's normal that they will prefer easy and semi-automated language like Python.

It would be interesting to hear from people maintaining code that came from these startups. I suspect they would have a very very different view of things :) Maybe something investors should think about? Ehh, who am I kidding...

This simple code and more time on hands to spend on promoting = successful startup. No one really cares about scaling YT-like app when it has 10 users.

Developers will handle that. And if they want jobs, startups must be made. As you might know, successful startups are made by less technical people mostly...

Re: Why People Should Learn Python

#296

If only the JVM didn't have slow startup speed I would almost exclusively write Groovy scripts. There is just something so awesome about shoving your dependencies right in the script and not worrying about pip, easyinstall, system libraries etc [1]. Maybe Java 10 will fix the startup speed (or whenever jigsaw is done correctly) but I doubt it. [1]: http://docs.groovy-lang.org/latest/html/documentation/grape....

> There is just something so awesome about shoving your dependencies right in the script

Groovy needs two lines (@Grab and import) to get a dependency. Golang only requires the import. Perhaps Groovy needs to be rewritten in Go.

Re: Why People Should Learn Python

#297
post #34

Why you shouldn't learn Python: 1. In-consistant syntax. 2. The language uses exceptions to control flow of logic. 3. Divided community, since Python 3+ included breaking changes to the standard. 4. Un-discoverable APIs. You better hope the documentation is bulletproof else the API could change in any which way during runtime. 5. Poor error messages. If an import goes wrong you are not told why, and so on. 6. Ultimat…

8. Significant whitespace. Not only is it a constant minor inconvenience when editing the program, it makes it very hard to cut-and-paste code fragments on the web.

Any editor with multiline support makes this problem go away (vim, sublime)

Re: Why People Should Learn Python

#298
post #82

Earlier quoted context omitted.

> Half the stories here are about Node.js. I think that might be a slight exaggeration. At present, zero of the stories on the HN front page appear to be about Node.js.

My last ten coin flips were heads, but overall, heads is roughly half.

The HN front page is 30 items. Of those, none were about Node.js when I made that comment. Right now, none are about Node.js and, though I don't trust my memory much, it's a largely different selection of items.

If half of all HN front page items were about Node.js on average, the probability of getting (let's say, conservatively) 40 with none about Node.js would be (1/2)^40 or about 10^-12.

Of course people exaggerate and I am fallible. If 30% of all HN front page items are about Node.js on average, the probability of getting at most one such item out of 40 is about 10^-5. Which is, y'know, still much less likely than ten consecutive heads when flipping a coin.

Re: Why People Should Learn Python

#299

Earlier quoted context omitted.

For those languages is not people who reindent code but it's the editor or the IDE. There is usually a key to force reindentation. That is possible because {} or even the end in Ruby are easy markers for the block (there are multiple markers for a block start in Ruby). Is there any automatical indentation function in some editor for Python? If not, it's Python the unfortunate language where people has to indent code…

> For those languages is not people who reindent code but it's the editor or the IDE. There is usually a key to force reindentation. Regardless of whom or what is doing the indentation, people still prefer reading code which is indented, even in a language which relies on braces or parenthesis for flow. The indenting is not for the compiler's sake, it has no problem understanding this: http://www.ioccc.org/2014/maffi…

How does it know that a line pasted to the end of a block from another indentation level belongs to that block or should go after the end of the block?

    if cond:
      line
  pasted line # where does it go?

Re: Why People Should Learn Python

#300

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…

This is where `collections.defaultdict` shines
Post reply on HN