News for hackers. Stuff that matters.

thehotelambush

Re:Clarity over brevity in variable and method names on Monday September 10, 2012 @02:54PM (#4501457)
Not to mention the increase in difficulty of remembering the variable names.
Re:Clarity over brevity in variable and method names on Monday September 10, 2012 @02:51PM (#4501438)
With the risk of RSI, I don't need to type any more than I already do. In a perfect world tab completion would exist everywhere and you could make arbitrarily long variable names. But do names like "make_person_an_outside_subscriber_if_all_accesses_revoked" really make your code more readable? There's only so much info you can put in a variable name, and I'd rather be able to see more code at one time on the screen that read a massively long name every few lines.
Certainly that's a motive too. And it's no secret that the government (in particular the NSA) has been amassing large swathes of data on what could be the entire population of the US.
ok, what I said was based on something I heard Julian Assange said in an interview from about a year ago. Apparently he hasn't given any proof for his statement (namely, that Facebook has an interface for government intelligence to use). I tend to believe what Assange has to say, but who knows.
The real reason for this isn't to improve comment quality; it's so they can store information on you more effectively and then sell it to the government. Facebook has a leg up on this because of how it started, but Google wants to level the playing field more and more.
Re:Poll: What's Your Favorite Programming Language? on Sunday March 25, 2012 @09:16PM (#3754492)
What the fuck is a stack?
Re:Why Python is Important for You on Saturday February 11, 2012 @07:59PM (#3580698)
Thanks for mentioning sets - this is another thing that I would like to be built-in in Ruby. But "list(set(mylist))" seems like kind of a hack.

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

Sure, you can write a library for anything and by now Python has libraries for most everything. But it still makes a difference to have things in the core language, plus a nice syntax for them.

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

This is a case of making up for odd semantic choices with special syntax, which then becomes an unnecessarily fixed-in-stone part of the language. Range objects in Ruby are actually like slice objects in Python. But Ruby separates the syntax for ranges from the get-item method, since there are plenty of other places where you would want to use ranges (then you can iterate and map over them, etc.).

Ruby uses blocks to implement things like an each method that fulfills the same function as Python's for statement. (Ruby has a for statement but it is hardly ever used.) In Ruby your example would be

countries.split(',').map &:strip

which is obviously more concise and no less readable. Compare with

countries.split(',').each &:foo

where foo is some side-effectful method.

IMO such a small change in behavior should result in a similarly small change in how the program is written.

Re:Why Python is Important for You on Saturday February 11, 2012 @06:25PM (#3580491)
This is the kind of reasoning that lies behind LFMs: that it is better to cater to someone who knows nothing about the language (but maybe has a few mainstream languages under their belt already) than to someone who has put in the work to understand it. I'd rather pay to learn a difficult but more abstract language feature just one time, than pay all the time for its absence.
Re:Why Python is Important for You on Saturday February 11, 2012 @06:15PM (#3580469)
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 operators" like each_with_index

-almost zero distinction between built-in classes and methods and user-written ones: you can open up Hash (dict) or Array (list) and extend it straightforwardly.

Downsides are:

-generally uglier and more ambiguous syntax

-distinction between functions and methods (b/c "all you can do is send a message") leads to a lot of unnecessary duplication of concepts

-so-called "blocks" which are really just a hack to avoid writing the word "lambda" a bunch of times (maybe if the more concise Ruby 1.9 syntax for lambdas had existed earlier blocks wouldn't have been implemented). I think they are based on the idea that most HOFs only require one functional argument, and they encourage functional programming, but they (along with the last bullet point) discourage the general case. They provide some of the functionality of macros.

-you can't define a class inside a method (still haven't quite figured out the reasoning behind this one).

In general Ruby is definitely more powerful than Python, but in its higher ambitions suffers more obviously from clashes between functional and OO programming. Python's dogmatic insistence on "readability" makes it feel like an old grandma in comparison to Ruby.