Live data from Hacker News

Why Python is Important for You

blaag.haard.se

91–100 of 231 posts

Re: Why Python is Important for You

#91
post #16

I am kinda afraid of getting down voted, but I have used Python and I feel like I get all this and more (CPAN) when using Perl. The major difference in my opinion is that Perl gives you even more freedoms, which causes you to need some self discipline, but you get stuff done even quicker that way. It feels a bit like Python is better for programming beginners or people that tend to be too lazy sometimes and Perl is f…

The point about static languages is definitely well-made. Python's two key aspects are its lack of dynamism, its structural rigidity, and... oh, THREE key aspects!, because I forgot its famously rigorous static type-checking system.

Coming from a C/C++ background myself, I found this very reassuring. I don't like languages that keep you constantly on your toes due to providing insufficient structure and too much dangerous freedom and flexibility.

Re: Why Python is Important for You

#92

My biggest problem with Python is that projects larger than a given size tend to become unmaintainable rather quickly. This is in large part because of the lack of strong typing and type annotations; if you aren't the only author or can't keep the codebase in your head, it takes real effort to figure out what a function does. Even the type annotations provided in a language like Java or C++ make this task much easier…

This is a significant problem for me as well, coming from C++ and Haskell. Even just going through and making a few changes here and there, there’s no way for me to know without extensive testing whether my edit was even remotely correct beyond a cursory syntax check.

I’ve never had to deal with testing all that heavily in statically typed languages, because I can rely on the type system to do a lot of very helpful static analysis. The lack of basic static knowledge about a Python program is frustrating and discomfiting, and ultimately discourages me from using the language for anything serious.

Re: Why Python is Important for You

#94
post #11

As a commenter on the article wrote: what about Ruby? I say this as a happy Python user. Ruby seems very similar but I'm reminded of a pg essay on language power: looking up the power curve, you see '$Language plus a bit of weird stuff that is probably irrelevant.' So I don't trust myself. As someone who loves Python and doesn't know any Ruby beyond a few bits of syntax and the obvious bits that are common to most la…

I used Python for a really long time and switched to Ruby several months ago. Benefits of Ruby are: -no distinction between expression and statement (everything has a value) -lambdas can thus contain any expression -much bigger range of built-in methods and classes (all permutations of a list, removing duplicates from a list, Rational class, Regexp class, Range class, etc.) -more flexible syntax and "control operator…

> -lambdas can thus contain any expression

why would you want to use lambdas if you have generator expressions? eg:

map(lambda c: c.strip(), countries.split(','))

vs

[c.strip() for c in countries.split(',')]

IMHO the latter one is way more readable and generators cover almost all the use cases for lambdas. If you could not do it with a generator expression and choose to use a anonymous function it should have been a method anyway.

> -much bigger range of built-in methods and classes (all permutations of a list, removing duplicates from a list, Rational class, Regexp class, Range class, etc.)

you mean sets, dictionaries(hashtables) etc.? those are built in as well in Python.

Remove duplicates: mylist = list(set(mylist))

Range class: [i for i in range(10)]

you can import the rational class via a simple from fractions import Fraction

same for regex

> -more flexible syntax and "control operators" like each_with_index

you can iterate over dictionaries with for k,v in dict.items()

if you need the index of a list you can use for i,v in enumerate(list)

personally I don't think there is much of a difference between Python and Ruby. One is more mature the other is way hipper and it comes down personal taste which one you choose.

Re: Why Python is Important for You

#95
post #87

Earlier quoted context omitted.

In my opinion Ruby has a slightly more obscure syntax with custom symbols, and it's C API is not as clean and well put together as Python's.

Which is more obscure? Reverse a string in ruby: string.reverse() Reverse a string in python: string[::-1]

Slice syntax in Python always bothered me. This would be slightly more readable:

    ''.join(reversed(string))
Except it requires you to have an idea of how iteration works (beginners don’t) and why that “join” needs to be there, and it’s still an order of magnitude slower. But hey. Ruby is prettier in some ways, Python in others, and beggars, as they say, can’t be choosers.

Re: Why Python is Important for You

#96
post #69
post #3

I like to call this cognitive compatibility - the amount of effort required from an uninitiated English-speaking observer to understand what a program does. Most people who are deeply familiar with a language will have a tendency to discount this effort, but really it is essential because it minimizes the translation layer that your brain has to use any time you read code. Python encourages code which is readable in…

Python code is superficially easy to read, but to know what a piece of code really does can be extremely hard, specially when metaclassed, generators and the like are involved. Also there is plenty of Python code that is not particularly readable even superficially, particularly convoluted uses of list comprehension come to mind. And I don't think 'consistency' is one of python's main qualities, when even in the stdl…

+1 for the metaclasses example... list comprehension doesn't seem that big a deal, but then am biased way too much.. Also agree with consistency part.... but personally python is beginning to lose some of it's charm with the move towards consistency...

Re: Why Python is Important for You

#97
post #87

Earlier quoted context omitted.

Which is more obscure? Reverse a string in ruby: string.reverse() Reverse a string in python: string[::-1]

Slice syntax in Python always bothered me. This would be slightly more readable: ''.join(reversed(string)) Except it requires you to have an idea of how iteration works (beginners don’t) and why that “join” needs to be there, and it’s still an order of magnitude slower. But hey. Ruby is prettier in some ways, Python in others, and beggars, as they say, can’t be choosers.

Way way slower than the slicing.

Re: Why Python is Important for You

#98
post #45
post #11

As a commenter on the article wrote: what about Ruby? I say this as a happy Python user. Ruby seems very similar but I'm reminded of a pg essay on language power: looking up the power curve, you see '$Language plus a bit of weird stuff that is probably irrelevant.' So I don't trust myself. As someone who loves Python and doesn't know any Ruby beyond a few bits of syntax and the obvious bits that are common to most la…

Ruby's blocks and built in regular-expressions are two examples of things you're missing. if result =~ /regex/ that kind of thing is awesome for readability, but it can also be pretty darn slow. There's also some interesting things about the ruby object model and interpreter that are different from python's approach. Whereas in the python REPL you type help(object) to get the docs on that object, in ruby you type obj…

ruby does have its share of cruft, but it also has some inspired features that make a far bigger difference than you'd think they would. blocks are the biggest (specifically, syntactic support for attaching a lexical closure to every method call, which the object can choose to use or not), but here's another cute one: the case statement

    case object   
      when matcher1; ...   
      when matcher2; ...   
    end
performs a method call on the matchers, with the object as an argument, rather than vice versa. so you can say things like

    case name
      when "John Smith"; puts "hello again"
      when / Smith$/; puts "are you related to john?"
    end
the string "John Smith" and the regexp / Smith$/ will each call a different matcher to see if they match your name - a far cleaner design than the string class having to provide matchers for everything you might want to use in a case statement.

Re: Why Python is Important for You

#99
post #61

"Weirder languages (e.g: Haskell)" sounds like something a Blub programmer would say. How is Haskell "weird"? I've used Python for many years, but only recently have I migrated my last Python niche (simple scripts) from Python to Haskell. I've found that even there, Haskell has become more productive.

> How is Haskell "weird"? Functional the world (of wide-spread computing languages) is imperative, lazy the world is eager, objects-less when the world is object-oriented, curried when the world is uncurried, pattern-matched when the world is conditional and brings up "strange" concepts from mathematical bowels like "monads", "functors" or "zippers" when the world barely iterates on arrays. How is Haskell not weird f…

The world is mostly parallel and asynchronous, yet most languages are sequential and synchronous. And the object-orientedness claim is overstated, as you drink from a cup, rather than use rather than think it in terms of cup.spill(), signals propagate, but 'return' is nowhere to be found... unless of course you are just talking about programming, but that's a bit of a circular argument.

Re: Why Python is Important for You

#100

Earlier quoted context omitted.

I used Python for a really long time and switched to Ruby several months ago. Benefits of Ruby are: -no distinction between expression and statement (everything has a value) -lambdas can thus contain any expression -much bigger range of built-in methods and classes (all permutations of a list, removing duplicates from a list, Rational class, Regexp class, Range class, etc.) -more flexible syntax and "control operator…

> -lambdas can thus contain any expression why would you want to use lambdas if you have generator expressions? eg: map(lambda c: c.strip(), countries.split(',')) vs [c.strip() for c in countries.split(',')] IMHO the latter one is way more readable and generators cover almost all the use cases for lambdas. If you could not do it with a generator expression and choose to use a anonymous function it should have been a…

> why would you want to use lambdas if you have generator expressions?

Lambdas (blocks) in Ruby are used for way, way more than just building or manipulating lists. For example, there is no need for the "with" keyword in Ruby, because you can just use blocks for that. As another example, you can specify a block to the Hash constructor to specify code that runs when a key is accessed that is not present.

> Range class: [i for i in range(10)]

That is not a range class, that is an expression for constructing a contiguous list of numbers. The Range class in Ruby is an actual class that you can instantiate and call methods on.

  ("a".."z").cover?("c")    #=> true
  ("a".."z").cover?("5")    #=> false
> personally I don't think there is much of a difference between Python and Ruby. One is more mature the other is way hipper and it comes down personal taste which one you choose.

They have similar capabilities but make very different choices in a lot of ways.

Post reply on HN