Live data from Hacker News

Why People Should Learn Python

iluxonchik.github.io

311–320 of 329 posts

Re: Why People Should Learn Python

#311
post #152
post #51

Earlier quoted context omitted.

Not all - note the always relevant: https://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/

That's not necessarily relevant. It's been rebutted point by point http://forums.devshed.com/php-development-5/php-fractal-bad-... , and PHP has undergone major changes since that was written.

That PHP has gone through major changes matters, and I agree that newer versions of PHP are huge improvements, but I don't think that response is an adequate rebuttal of the Fractal of Bad Design article. The "rebuttal" is closer to apologetics, and it starts out by basically denying the idea that language design matters.

Admittedly, the author of that post lost me pretty early on when he said that languages don't need to be predictable, it's on developers to learn everything about how and why a language implemented things they way they're implemented, and complaining just means you're lazy. Sorry, but when I can guess at syntax in Python or Ruby and be right(because the languages were designed to be predictable and consistent), I don't want to consult arcane documentation in PHP to figure out why things don't work the way I expect them to work.

The author is also pretty rude and flippant, often when he's not even right. He ignores things like the Fractal author explicitly saying that Wikipedia and Facebook have very smart developers, so he can say that the PHP "community of amateurs" comment was about those developers. Pretty disingenous.

He repeatedly complains that the author "doesn't understand" "loosely typed" languages, but never considers that maybe the author understands them but thinks they're bad design, hence the whole "fractal of bad design" in the name of the post?

Re: Why People Should Learn Python

#312

Earlier quoted context omitted.

And in Python you can write something like: sum([p.price for p in products if p.type == "x"]) Excuse untested code from phone, but I like it better than the ruby version.

FYI, you can leave off the square brackets for a small performance boost. That turns it from a list comprehension into a generator expression, which is lazily evaluated and doesn't create a list container (which would immediately be thrown out anyway). It's like the difference between range(n) and xrange(n).

Nice, thanks for the tip.

Re: Why People Should Learn Python

#313
I read lots of people complaining about medium-to-large scale Python projects, due to lack of static typing. Aren't people using reflection and dynamic in C#? As soon as the code touches such run-time features, the testing at run-time is essential.

I wonder how large projects such as OpenStack, Django, Edx, PyPy deal without static types?

Re: Why People Should Learn Python

#314
post #240

Earlier quoted context omitted.

Reduce doesn't have side effects, handles an empty collection, doesn't need to reference the index of the iterable, and self-documents the code as a fold. I find the last part nice because a loop or a Python comprehension would need to add a comment to explain what would otherwise be clear from the syntax. Here's an alternative example where I think it makes sense (checking if the size of all elements in a collection…

I don't think that does what you think it does: >>> reduce(lambda a, b: len(a) == len(b), ["a", "b", "c"]) Traceback (most recent call last): File " ", line 1, in File " ", line 1, in TypeError: object of type 'bool' has no len() It's trying to do len(len("a") == len("b")) == len("c"), which becomes len(True) == len("c"), and len(True) doesn't work. Some variations which do work are: len(set(map(len, ls))) == 1 len(s…

Ouch, good catch! I can't think of a nice way to salvage reduce but these are some clever alternatives. Point anti-reduce.

Re: Why People Should Learn Python

#315

Earlier quoted context omitted.

"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!

Have you tried working with Laravel 5.2+ ? Instead of doing tons of for-loops, etc.. You can easily create a collection from data and process it. For example using the DB class to get data returns an array of Std objects. For a legacy app I'm working w/ --it needs to be an array of arrays... I could for loop, and then add each to a new array.. or I can simply do: $data = DB::table('something')->where('something')->ge…

Laravel is still horse shit that does not follow good OOP practices.

Static calls and active record are not good OOP. Neither are Std objects.

Have a look at doctrine if you need an ORM. Otherwise read up on DDD and SOLID.

Re: Why People Should Learn Python

#316
post #307

Earlier quoted context omitted.

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 always though the recommended way to handle that split was by using setup.py as the Gemfile equivalent with very loose versioning rules, and for the Gemfile.lock case to not edit requirements.txt but to only generate it from pip freeze (or whatever it was - I haven't used Python for a while).

Yeah I've heard people say this as well, but from my understanding setup.py is more aimed at libraries than end user projects. I¨ve never seen anyone use setup.py for an end user project in any case.

Interestingly enough in Ruby it's the reverse, you use gemspec for gems which doesn't have the concept of locking. Instead you are supposed to specify semver conforming version patterns and then resolution of these happens when the gem is installed. Only end user projects use Gemfile.lock

Re: Why People Should Learn Python

#317
post #240

Earlier quoted context omitted.

I don't think that does what you think it does: >>> reduce(lambda a, b: len(a) == len(b), ["a", "b", "c"]) Traceback (most recent call last): File " ", line 1, in File " ", line 1, in TypeError: object of type 'bool' has no len() It's trying to do len(len("a") == len("b")) == len("c"), which becomes len(True) == len("c"), and len(True) doesn't work. Some variations which do work are: len(set(map(len, ls))) == 1 len(s…

Ouch, good catch! I can't think of a nice way to salvage reduce but these are some clever alternatives. Point anti-reduce.

This doesn't salvage it in any meaningful sense, but it does work:

  class EqualLengths:
    def __init__(self, size):
      self.size = size
    def __nonzero__(self):
      return True
    def __repr__(self):
      return "True"
  
  def equal_lengths(a, b):
    if isinstance(a, EqualLengths):
      if a.size == len(b):
        return a
      return False
    if a is False:
      return a
    n = len(a)
    if n == len(b):
      return EqualLengths(n)
    return False

  >>> reduce(equal_lengths, ["a", "b", "cc", "d"])
  False
  >>> reduce(equal_lengths, ["a", "b", "c", "d"])
  True
However, I could do something similar with sum():

  class SumEqual:
    def __init__(self):
      self.size = None
      self.is_equal = True
        
    def __add__(self, other):
      if self.is_equal:
        if self.size is None:
          self.size = len(other)
        else:
          self.is_equal = (self.size == len(other))
      return self
      
    def __nonzero__(self):
      return self.is_equal
      
    def __repr__(self):
      return repr(self.is_equal)


  >>> sum(["a", "b", "cc", "d"], SumEqual())
  False
  >>> sum(["a", "b", "c", "d"], SumEqual())
  True
and unlike the first case, this sum() solution will work when there are fewer than two items in the list.

Re: Why People Should Learn Python

#318
post #74

Earlier quoted context omitted.

At a glance, it looks like all languages are reasonably well loved except PHP and Node.js (shouldn't this just be Javascript? Does having a different standard lib make it a different language?) I think that's due to people having flash backs to terribly written code in both languages. For example, PHP apps pre-2005 rarely if ever used frontend controllers, preferring instead to twine in configuration and helper funct…

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)

> over engineered and almost looking like Java (just take a look at the latest Guzzle PHP Library)

Guzzle doesn't look that bad. It looks like requests from Python, but you have to create a client first.

> $client = new Client(['base_uri' => 'http://httpbin.org']);

> $response = $client->get('http://httpbin.org/get');

Or in Python

> response = requests.get('http://httpbin.org/get')

Re: Why People Should Learn Python

#319
post #296

Earlier quoted context omitted.

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

> Groovy needs two lines (@Grab and import) to get a dependency. Golang only requires the import. Perhaps Groovy needs to be rewritten in Go. I'm not dissing Golang but it isn't even remotely the same. A major portion of the OP content was about using Python instead of shell scripts. Golang is not scripting language. You need to compile for each platform and the code is opaque once it is compiled. Not to mention Gola…

> I'm not sure if you just mistyped

I didn't mistype. Go would make a good language for writing dynamic languages such as Apache Groovy in. My own Gro is just one example of such a dynamic language.

Re: Why People Should Learn Python

#320
post #205
post #128

Earlier quoted context omitted.

Reasons to learn Python: Sklearn, tensorflow, pandas, Sqlalchemy, requests, Beautifulsoup, numpy, scipy, pulp. If you have a language that had equivalent libraries that cover all these domains I'd love to hear it. Until then I can build really cool stuff in Python very easily thanks to the amazing hardwork and generosity of these library creators.

If you have a language that had equivalent libraries that cover all these domains I'd love to hear it. R[1]. [1] https://cran.r-project.org/

You can't possibly claim that the R language is better-designed that python...
Post reply on HN