Live data from Hacker News

Why People Should Learn Python

iluxonchik.github.io

301–310 of 329 posts

Re: Why People Should Learn Python

#301

Earlier quoted context omitted.

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…

Yep. What drives me even more crazy is things which are purely syntactically wrong, e.g. an else: clause with no if before it are only detected when the interpreter gets to that line.

Re: Why People Should Learn Python

#302

Earlier quoted context omitted.

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…

Java and Python are apples and oranges - one is a compiled language, the other is interpreted. Better to look at other interpreted languages like Ruby & Perl...and they have the same issue. It's a side-effect of using an interpreted language, but it also allows such languages to be self-modifying which can be very powerful when you need it.

Perl actually has a 'compilation' phase where some types of syntax errors are actually detected before it goes executing the code.

Re: Why People Should Learn Python

#303
post #99

Earlier quoted context omitted.

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.

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

I'm a php dev, and as much as I try going to Rails/Django -- I keep coming back to Laravel. W/ Laravel + composer PHP finally grew up, wordpress is a hacky out-dated should-be-shot-and-replaced beast. The best way of modern web dev in my opinion is to use Vue or Angular for the frontend, and laravel as a backend. PHP 7.0 is extremely fast and proficient, and it's an easy framework to pick up.

If you need anything more resilient server side then I'd recommend using a Golang or Elixir framework like Phoenix which has multi-threading.

Re: Why People Should Learn Python

#304

Earlier quoted context omitted.

Maven Central says it's around 4.4MB (with some things still pending to be dropped before the release of the final version)[1]. [1] https://mvnrepository.com/artifact/org.scala-lang/scala-libr... I would disagree with the comment on verbosity compared to Java 8/Haskell/Ocaml. Most of the things I do regularly in Scala would require a magnitude of more code. Ocaml doesn't even have higher-kinded types or implicits, so…

I'm not sure I like implicits as for HKT... "with great power comes...". HKTs are great for a generic library writer (aka standard library) but I think the over abstract nature ends up confusing your average developer. You basically have your type aficionados obfuscating the codebase for developers who can barely handle generics. It is sort of analogous to using massive reflection / meta-programming in scripting lang…

The great about types in Scala is that complex solutions to complex problems can be contained and don't infect the rest of the codebase.

The average programmer can enjoy completely consistent names and signatures across different libraries, without having to know that the consistency comes from one method being applicable to various types, not manual labor repetitiously adding the same method to different types which can drift apart at any time without anyone noticing.

HKTs are not that expensive. Slow compile times are usually caused by people doing Prolog at the typelevel in Scala.

Re: Why People Should Learn Python

#305
post #230

Earlier quoted context omitted.

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

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')->get();

return collect($data)->map(function($x) { return (array) $x });

There's a talk at lara-con on using collections to replace just about all loops, and it's pretty insightful and makes code so much more readable and enjoyable.

PHP by itself can be ugly -- but the Laravel community has created something beautiful from what used to be akin to horse shit.

Re: Why People Should Learn Python

#306
post #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.

> 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 Golang might not have dependency issues at runtime but the overarching consensus is that certainly has issues with compile time dependencies management (auto checking stuff out from github is not effective).

> Perhaps Groovy needs to be rewritten in Go.

I normally don't say this... but that is just dumb fanboy comment.

EDIT: apparently you are working on a scripting language powered by Go called Gro. I'm not sure if you just mistyped and meant Gro instead of Go.... and reading your blog it seems you must have been severely burned by the Groovy community.

Re: Why People Should Learn Python

#307

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

Re: Why People Should Learn Python

#308

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.

I guess it's a personal style choice, the Python code is more performant(less iterations over the data set), but I like the ruby version better.

It's only one iteration if you throw a .lazy in there:

products.lazy.select { |product| product.type == 'x' }.map(&:price).reduce(:+)

Re: Why People Should Learn Python

#309
post #87

I was a long time Rubyist but switched over to Python because even though its characteristics and philosophy made me reflexively shirk it at first -- particularly significant whitespace, one-line-lambdas, and the clusterfuck of 2.x vs 3.x -- it seemed to me to be an obviously easier language to teach , nevermind its significantly stronger libraries for numerical work. I'm glad I made that decision. The language was e…

As a Ruby fan who is baffled by Python's continued popularity, I like this comment - I'm always interested to hear why people have such different experiences than me trying to move from the former to the latter.

That said, unless "recently" was years and years ago, Date#next_month is a thing:

  require 'date'
  date = Date.today
  while (date 
One thing that I think throws a lot of people is that the official Ruby docs are actually better than Google for figuring stuff like this out - it only takes a couple minutes to find #next_month by perusing the method listing at http://ruby-doc.org/stdlib-2.3.1/libdoc/date/rdoc/Date.html, but do a web search and you get a bunch of Railsy crap.

Though I will grant you that even searches on ruby-doc.org keep bringing up results for Ruby 2.0.x and whatnot. That part is pretty bizarre.

Re: Why People Should Learn Python

#310

Earlier quoted context omitted.

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…

Java and Python are apples and oranges - one is a compiled language, the other is interpreted. Better to look at other interpreted languages like Ruby & Perl...and they have the same issue. It's a side-effect of using an interpreted language, but it also allows such languages to be self-modifying which can be very powerful when you need it.

Python and Java are both compiled to bytecode and both interpreted as bytecode. It has absolutely nothing to do with compilers.
Post reply on HN