Live data from Hacker News

Why People Should Learn Python

iluxonchik.github.io

171–180 of 329 posts

Re: Why People Should Learn Python

#171
post #139
post #134

Earlier quoted context omitted.

I've never understood this complaint. Whitespace is included when you copy something. What's the problem? Admittedly it is mildly annoying when someone decides to use some random number of spaces for indentation, and you have to fix it to make it match the rest of your code (my preferred editor, Geany, has a feature for this). We should all just use tabs. But "very hard"?

The web collapses whitespace so if the code is not in tags you are stuck. This is quite often a case where comment systems were not intended to share code.

It's Python's fault for not retrofitting its syntax to satisfy a markup language invented years later?

Re: Why People Should Learn Python

#172

Earlier quoted context omitted.

What do you guys mean by dependency locking? What I do with pip is add a requirements.txt with things like: Django~=1.10.0 And it keeps the env autoupdated with the latest patch revision but not the latest minor revision. pip-tools doesn't seem to do much related to that, no?

The problem with that is that you no longer have reproducible builds. If you checkout a year old commit and built deployment artifacts with it you want the resulting artifact the be the same as when it was created. This is what you get with Bundler and the Gemfile/Gemfile.lock split You put gem 'rails', '~> 4.2.7' in your Gemfile and when you run `bundler install` the exact version of rails you ended up resolving wit…

I version my docker images. Inside the Dockerfile I usually install the latest version (i.e. pip install without specifying version). By single version bump of my image version I can trigger update of everything.

If I check out an old commit I can look up docker image version in the source control, download exactly the docker image that was running at that time and start shell in this image. Inside the image I can run "pip freeze" to check exact version of each package that was running at that time. I can then update the old Dockerfile with those specific versions by adding the "==x.y.z" e.g. "pip install oauth2client==3.0.0" in the pip install to reproduce the old build.

Additional benefit is that such scheme works for system packages, or for any other language libraries I can think of.

Re: Why People Should Learn Python

#173
post #134
post #34

Earlier quoted context omitted.

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.

I've never understood this complaint. Whitespace is included when you copy something. What's the problem? Admittedly it is mildly annoying when someone decides to use some random number of spaces for indentation, and you have to fix it to make it match the rest of your code (my preferred editor, Geany, has a feature for this). We should all just use tabs. But "very hard"?

> Whitespace is included when you copy something. What's the problem?

In addition to the points posted in a parallel thread, selecting and copying leading whitespace reliably is more difficult than just getting the printable characters. Also: it's not something that anyone has any cause to do outside of copying Python text.

Re: Why People Should Learn Python

#174
post #99
post #74

Earlier quoted context omitted.

just to chime in on this, modern PHP is nothing like what people remember from the pre ROR days, i still use it to this day and the major frameworks and libs are really well written to the point i feel some are even over engineered and almost looking like Java (just take a look at the latest Guzzle PHP Library)

As my PHP fluent colleague said to me - don't bother learning PHP or you will end up having to fix (our) Wordpress sites and thats a nightmare. We have a Python application, and while its not written well, the PHP sites we have seem to be a fair bit worse even the ones not done in Wordpress.

Which is a shame. I recently started toying with C#, and most of the syntax is eerily similar to PHP7. Obviously the standard library is completely different, but so far I'm right at home with the core language (though I haven't explored more advanced features yet).

Luckily I'm currently working with a PHP7 app, so all is good, but my next app will likely not be PHP at all.

Re: Why People Should Learn Python

#175

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…

This is so true. I often think that people only need to put the word 'Rust' into the title to get a ton of up votes. Maybe because rust is a great game as well as being a popular programming language ;)

Re: Why People Should Learn Python

#177
post #43

I switched to writing python as my main backend/scripting language with my new job. Previously I was using Ruby for most of this stuff with some Go. I must say that so far Python has been a vastly inferior experience for me. The languages are fairly similar all though I prefer the more talkative/english style of ruby and the use of functions over list and dict comprehension. The thing that really stands out to me tho…

Amazing that Python 2 vs. Python 3 has still not yet been sorted out. I dipped my toe into Python a couple years ago when looking for a general-purpose scripting language and quickly gave up in frustration—Python 3 was by far the preferable flavor, but many libraries simply didn't work. I picked up Ruby and haven't looked back.

Re: Why People Should Learn Python

#178

> Another thing is strict typing and debugging: since Python is an interpreted language, finding bugs wasn’t as easy Wait, what? How is its interpreter remotely relevant to its semantics? > if you have a syntax error in C, the program will simply not compile, on the other hand, in interpreted languages, the problem might go unnoticed for quite some time Hang on--Python allows you to run code that has syntax errors? I…

To my knowledge syntax within a file is completely checked when that file is loaded. I think the OP referred more to errors in method and other reference names.

If you write this:

  #!/usr/bin/python
  import time
  time.sleep(5)
  fdafadsfadsf
It'll take 5 seconds to crash with a "NameError: name 'fdafadsfadsf' is not defined". Likewise, if you do this:

  #!/usr/bin/python
  import time
  x = 1
  time.sleep(5)
  print "x is "+x
It'll take 5 seconds to crash with "TypeError: cannot concatenate 'str' and 'int' objects"

In a language like Java, these would be syntax errors, and they'd be picked up at compile time as they're illegal in Java's syntax.

I assume they're legal in Python's syntax, because for all the syntax checker knows, time.sleep() might define fdafadsfadsf and convert x into a string. So they're runtime errors in Python.

Of course, Java still has runtime exceptions - null pointer exceptions, for example.

Re: Why People Should Learn Python

#179
post #146

Earlier quoted context omitted.

I find chained enumerator / block style code much easier to write and understand than list / dict comprehensions too. It's probably the single biggest thing that I don't like about Python; lambdas are simply too awkward, but lambdas + monadic transformations are probably my primary mental abstractions for writing software these days.

Could you give an example of that?

Think: bash shell pipes. Transforming input to output through successive filters and projections, applied in a concatenated fashion and developed interactively in a REPL. Model algorithms as transformations or compositions of the same, where possible, applied to lazy or eager iterators or consumers (the dual of an iterator, that acts as a sink for output) as required. Model data sources and sinks (like databases and network streams) as iterators and consumers. Program by building a data flow graph out of increasingly sophisticated (by composition) stateless widgets, rather than imperative loops etc.

Re: Why People Should Learn Python

#180

As the author mentioned Python is good for small stuff. If you are building a huge system where the jobs are spread between a dozen of people things could easily get out of control and you could end up in the dirt.

Do you feel this way due to the dynamically typed nature of the language (and the possibility of having ambiguous interfaces)? I've had pretty good luck with rather large scale python projects, though we've been pretty strict about working within a framework.
Post reply on HN