As if marriage had anything to do with sex. You'll find out soon, my son.
Re:The greatest game...the best AI..highest realis
on
A Gamer's Manifesto
·
· Score: 0, Troll
The reason is because for them to win we just have to leave, for us to win we have to establish a functional democracy and then leave.
Would you first establish a functional democracy in your own country, please? Or did you mean puppet regime? Well, you've already established the previous one in Iraq. That didn't turn out so well, did it?
Here, though, it's even worse - as the bikes are for rental, they're depriving the owners of the chance to make money.
Well, because the bike wasn't locked properly they couldn't have used it anyway to make money. Because they got a security auditing for free, they actually MADE money.
This is no different to walking in to a Blockbuster or similar and walking out with a couple of DVDs without paying. Even if you do return them later, it's still wrong, morally and legally.
They didn't walk out with anything, they actually left a lot of stuff in the shop. I think this is a very good deed, especially morally.
No bikes were stolen or harmed in the making of this hack. They are all back in service, although they can be driven by the hackers without paying the fee. A very elegant hack indeed.
I am also grateful to the guys who made it public, how easy it is to open Kryptonite or Kensington locks, because if I would have to further believe the companies' public statements, I'd be in real danger of losing my property. And the bastards of Kryptonite that knew for a decade, how easy their locks can be opened wouldn't have paid me a dime, because it obviously wasn't cracked open.
The Bahn should be grateful, too. They could use the chip's lockbit and try to make the system even more secure (it wasn't so bad to begin with) instead of whining because their bragging was debunked as marketing drivel.
"someone elses' property" wasn't adequately secured (despite the company's public bragging) and paying a security company to do the job they did for free (for the challenge, that is) would have been much more expensive. The actually spent money on doing that and they didn't destroy anything. Why the fuck was this article modded up?
Well, you should consider that Ruby's number tower supports arbitrary precision arithmetics with autoconversion, so you will never have an integer overflow in Ruby. I guess that Ruby's Bignum methods are faster than the Perl's Math::BigInt, while computing with smaller integers should be faster in Perl.
You don't have list comprehensions in SML. Last time I checked, this was still a functional language.
The comp.lang.functional FAQ says
Functional programming is a style of programming that emphasizes the evaluation of expressions, rather than execution of commands. The expressions in these language are formed by using functions to combine basic values. A functional language is a language that supports and encourages programming in a functional style.
Actually Ruby only has expressions, so it seems to be a pretty good candidate. You can also
create functional objects and use them as arguments:
def add(x, y) x + y end
(1..10).inject &method(:add) # => 55
The same in Common LISP, also a functional programming language:
And he's very poor at actually getting the public to accept him.
What are you talking about? Putin's got 71% of the vote at this year's russian presidential elections. That's a number the american dictator can only dream of.
But it's absolutely unclear what it does if the reader doesn't know what compareTo and compare are supposed to return. This program is so horrible: lots of unecessary comments and the comments that are required to understand it, aren't there.
The funny thing is, that it uses generics and the new for (a : b) construct, otherwise it would look even more horrible with casting and iterator verboseness. That's one of the main weak points of Java: It requires lots of unecessary keywords to do the easiest things. It doesn't support codeblocks, so the programmer has to define an anonymous inner class and declare the variables final if they are to be used in the closure. And the stupid comments make the purpose of the program even more unclear.
That's an example of clear and short code (in Ruby of course):
count = Hash.new(0) ARGF.read.scan(/[A-Za-z]+/) { |word| count[word.downcase] += 1 } # Sort words most frequent first, than lexicographic order and print # the results. count.sort_by { |word, count| [ -count, word ] }.each do |word, count|
printf "%7d\t%s\n", count, word end
I think it's OK, if small scripts use implicit $_ to get the job done fast. But if programs get more complex, Perl gets into your way more often because of the context sensitivity.
Consider this code snippet:
while () {
chomp;
do_something();
print;
print "...\n"; }
Now if do_something does something like this, you have a big problem:
sub do_something() { $_ = 'void'; }
Ruby shines in that area, because small scripts can be refactored to more complex programs very easily.
If you want to move your script from an imperative style to a more class based object oriented design, you can just begin to add class definitions like
class A
attr_accessor:a
end
class B A end
b = B.new b.a = 1 puts b.a
at the top of your script. In Perl you have to go through lots of @ISA-orgies and have to define default constructors and accessors manually. And you end up pretty fast with a big mess.
The interactive Ruby mode isn't built into the interpreter. It's a Ruby program nameed "irb" that is distributed with Ruby. It is also more comfortable than your little try, it has got a history, a builtin Ruby Lexer and usually calls the inspect method for every object.
Perl has built in something like an interative mode, try this:
perl -de1
But in comparison to Ruby's it sucks, and I rarely use it while I use the irb the whole time. Perhaps it is also more useful because Ruby's introspection possibilites are so much better than Perl's, that is: you can find out the instance methods of an object that begin with "a" by typing "object.methods.grep/^a/" into irb. Or you can find out all the instance variables of object by typing "object.instance_variables"
So I disagree, Perl would need an interactive mode, and to be really useful it would need an object model that isn't totally fucked up.
The |x| is a block parameter list. Blocks are Ruby's way to emulate higher order functions.
[ 1, 2, 3 ].each { |x| puts x }
would print "1", "2" and "3" in three different lines.
The block parameters are very clever, you can also put something else than only variables there. If you want to compute the sum of the products of some pairs, you could do it that way:
a = [[1, 4], [2, 5], [3, 6]] sum = a.inject(0) { |s, (x, y)| s + x * y }
The block would first be called with s = 0 and (x, y) = [1, 4], that would assign x to 1 and y to 4.
The inject would compute s = 0 + 1 * 4 s = 4 + 2 * 5 s = 14 + 3 * 6 = 32 by calling the block three times once for every pair in the list and adding the results in the s and returning the result s.
The ||-syntax looks very similar to the Smalltalk syntax for local variables. Ruby is very strongly influenced by Smalltalk. The inject method name stems also from Smalltalk. You can use blocks to make sure something is done after a block of code has been executed instead of using destructors or finalizers. An example would be to close a file after reading it:
File.open("/etc/passwd") do |f|
puts f.read.count("\n") # => number of lines end # => file f is closed here
do...end is equivalent to { } and usually used if the block is not an oneliner. Readability is actually very important in Ruby culture.
Ruby has an exception handling that is very similar to Python's, but the keywords seem to be blatantly stolen from Eiffel's Design By Contract. The transaction example from above could also be coded that way in Ruby:
t = start_transaction() begin
do stuff with t
more stuff rescue => e
puts "Caught an exception: #{e}" ensure
t.end_transaction end
I don't think that Ruby has a problem wth "non-alphanumeric" characters - it uses them very wisely, actually. I remember that Python uses lots of __foo__ and """bar""" - that really makes me feel uncomfortable when I have to read Python code!
f(x) = O(g(x)) as x approaches infinity means that
lim_x -> infinity abs(f(x)/g(x)) = c, where c is constant.
So it's bullshit to write something like O(2) because you can multiply the c with 2 and you would get another constant. Those functions would thus belong to the same class of asymptotic behaviour: O(1).
This is much better readable than Java's anonymous inner classes trick:
add_listener do... end
Java also forces you to declare variables from the outer environment as final if you want to use them in your method. So it's NOT possible to do something like that in Java:
called = 0 add_listener do
called += 1
puts "Called " + called + " times." end
But java is also inconsistent in this respect because at the same time it's possible to work around this arbitrary limitation:
class IntCollection {
private int[] collection = null;
IntCollection(int ary[]) {
collection = ary;
}
public void each(Runnable block) {
for (int i = 0; i < collection.length; i++) { block.run(); }
}
}
class foo {
public static void main(String args[]) {
int[] ary = new int[10];
for (int i = 0; i < 10; i++) { ary[i] = i; }
IntCollection col = new IntCollection(ary);
final int count[] = new int[1];
col.each(new Runnable() {
public void run() { count[0]++; }
});
System.out.println("Counted " + count[0] + " elements.");
}
}
Only God knows why the Java language designers made such an obscure decision.
Re:Former perl, python, java geek gone to Ruby
on
Ruby 1.8.0 Released
·
· Score: 1
I suspect that an iterator could reuse the same block without breaking the semantics, but in any case I'm not strongly motivated by perfomance in this context.
I'm not sure: a Proc object is a closure and some memory most be allocated for the environment. In a block it's easy because the environment is always the current environment.
Easy. Hashes have "=>"; blocks don't.:)
Not necasserily, {:a,1,:b,2} is also possible and blocks and hashes could also include hashes. One has really to look into the parser source to find out if that's so easy. And then it's necessary to convince Matz which isn't easy either (and this is a good thing I'd say). I think Perl has grown to be such an ugly beast because too much strange,
inconsistent and unecessary syntax has been included. I'm not too optimistic that Perl6 does a better job here.
I worked in one shop where the style was to initial everything (e.g. identifiers of the form MQR.____) "to avoid name conflicts" and "so you always know who to talk to if it's broken"!
LOL! That's code ownership! And I suppose people still were cursing programmers that have left the company several years ago.
Re:That's not what we mean by clean, friend.
on
Ruby 1.8.0 Released
·
· Score: 2, Informative
Clean syntax is not an end in itself. It's good for compiler writers because it's easier for them to parse the language. LISP and Brainfuck have a very clean and minimal syntax but the programmers have to pay a price. Ruby was not intended to be a minimal, clean language (like many academic languages are) but was designed to help programmers write better programmes and make them better programmers at the same time.
Matz held a talk on his intentions at OSCON (and it's fun to read) named
It's about time, that someone posts a link to "Erlang, the Movie"! So here it comes:
http://www.youtube.com/watch?v=uKfKtXYLG78
Yeah, I hear a lot of Anonymous Cowards are switching to Python recently.
As if marriage had anything to do with sex. You'll find out soon, my son.
The reason is because for them to win we just have to leave, for us to win we have to establish a functional democracy and then leave.
Would you first establish a functional democracy in your own country, please? Or did you mean puppet regime? Well, you've already established the previous one in Iraq. That didn't turn out so well, did it?
Here, though, it's even worse - as the bikes are for rental, they're depriving the owners of the chance to make money.
Well, because the bike wasn't locked properly they couldn't have used it anyway to make money. Because they got a security auditing for free, they actually MADE money.
This is no different to walking in to a Blockbuster or similar and walking out with a couple of DVDs without paying. Even if you do return them later, it's still wrong, morally and legally.
They didn't walk out with anything, they actually left a lot of stuff in the shop. I think this is a very good deed, especially morally.
No bikes were stolen or harmed in the making of this hack. They are all back in service, although they can be driven by the hackers without paying the fee. A very elegant hack indeed.
I am also grateful to the guys who made it public, how easy it is to open Kryptonite or Kensington locks, because if I would have to further believe the companies' public statements, I'd be in real danger of losing my property. And the bastards of Kryptonite that knew for a decade, how easy their locks can be opened wouldn't have paid me a dime, because it obviously wasn't cracked open.
The Bahn should be grateful, too. They could use the chip's lockbit and try to make the system even more secure (it wasn't so bad to begin with) instead of whining because their bragging was debunked as marketing drivel.
And he who cannot read should not try to write either...
Actually the bit wasn't even used. Why are you making such things up?
"someone elses' property" wasn't adequately secured (despite the company's public bragging) and paying a security company to do the job they did for free (for the challenge, that is) would have been much more expensive. The actually spent money on doing that and they didn't destroy anything. Why the fuck was this article modded up?
You still don't seem to get why hackers do the things they do. I doubt you ever will...
Yeah, sure it is turing complete. It also has a self -hosted interpreter, that's of course always a sign of a rather mature language.
You seem to be stuck in the Turing Trap. That can easily lead to another verification of Greenspuns 10th Rule of Programming. Try to find out how to beat the averages, please.
Following this logic and given there were enough libraries for brainfuck available, we could program everything in brainfuck as well?
Well, you should consider that Ruby's number tower supports arbitrary precision arithmetics with autoconversion, so you will never have an integer overflow in Ruby. I guess that Ruby's Bignum methods are faster than the Perl's Math::BigInt, while computing with smaller integers should be faster in Perl.
The comp.lang.functional FAQ says Actually Ruby only has expressions, so it seems to be a pretty good candidate. You can also create functional objects and use them as arguments:The same in Common LISP, also a functional programming language:Doesn't look so different, does it?
Of course:
Ruby = Class.new
# => Ruby
ruby = Ruby.new
# => #
ruby.is_a? Object
# => true
And he's very poor at actually getting the public to accept him.
What are you talking about? Putin's got 71% of the vote at this year's russian presidential elections. That's a number the american dictator can only dream of.
But it's absolutely unclear what it does if the reader doesn't know what compareTo and compare are supposed to return. This program is so horrible: lots of unecessary comments and the comments that are required to understand it, aren't there.
The funny thing is, that it uses generics and the new for (a : b) construct, otherwise it would look even more horrible with casting and iterator verboseness. That's one of the main weak points of Java: It requires lots of unecessary keywords to do the easiest things. It doesn't support codeblocks, so the programmer has to define an anonymous inner class and declare the variables final if they are to be used in the closure. And the stupid comments make the purpose of the program even more unclear.
That's an example of clear and short code (in Ruby of course):
count = Hash.new(0)
ARGF.read.scan(/[A-Za-z]+/) { |word| count[word.downcase] += 1 }
# Sort words most frequent first, than lexicographic order and print
# the results.
count.sort_by { |word, count| [ -count, word ] }.each do |word, count|
printf "%7d\t%s\n", count, word
end
You can translate this into Ruby pretty easy:
:a
while readline do
chomp!
print
print "...\n"
end
I think it's OK, if small scripts use implicit $_ to get the job done fast. But if programs get more complex, Perl gets into your way more often because of the context sensitivity.
Consider this code snippet:
while () {
chomp;
do_something();
print;
print "...\n";
}
Now if do_something does something like this, you have a big problem:
sub do_something() { $_ = 'void'; }
Ruby shines in that area, because small scripts can be refactored to more complex programs very easily.
If you want to move your script from an imperative style to a more class based object oriented design, you can just begin to add class definitions like
class A
attr_accessor
end
class B A
end
b = B.new
b.a = 1
puts b.a
at the top of your script. In Perl you have to go through lots of @ISA-orgies and have to define default constructors and accessors manually. And you end up pretty fast with a big mess.
The interactive Ruby mode isn't built into the interpreter. It's a Ruby program nameed "irb" that is distributed with Ruby. It is also more comfortable than your little try, it has got a history, a builtin Ruby Lexer and usually calls the inspect method for every object.
/^a/" into irb.
Perl has built in something like an interative mode, try this:
perl -de1
But in comparison to Ruby's it sucks, and I rarely use it while I use the irb the whole time. Perhaps it is also more useful because Ruby's introspection possibilites are so much better than Perl's, that is: you can find out the instance methods of an object that begin with "a" by typing "object.methods.grep
Or you can find out all the instance variables of object by typing "object.instance_variables"
So I disagree, Perl would need an interactive mode, and to be really useful it would need an object model that isn't totally fucked up.
The |x| is a block parameter list. Blocks are Ruby's way to emulate higher order functions.
[ 1, 2, 3 ].each { |x| puts x }
would print "1", "2" and "3" in three different lines.
The block parameters are very clever, you can also put something else than only variables there. If you want to compute the sum of the products of some pairs, you could do it that way:
a = [[1, 4], [2, 5], [3, 6]]
sum = a.inject(0) { |s, (x, y)| s + x * y }
The block would first be called with s = 0 and (x, y) = [1, 4], that would assign x to 1 and y to 4.
The inject would compute
s = 0 + 1 * 4
s = 4 + 2 * 5
s = 14 + 3 * 6 = 32
by calling the block three times once for every pair in the list and adding the results in the s and returning the result s.
The ||-syntax looks very similar to the Smalltalk syntax for local variables. Ruby is very strongly influenced by Smalltalk. The inject method name stems also from Smalltalk. You can use blocks to make sure something is done after a block of code has been executed instead of using destructors or finalizers. An example would be to close a file after reading it:
File.open("/etc/passwd") do |f|
puts f.read.count("\n") # => number of lines
end # => file f is closed here
do...end is equivalent to { } and usually used if the block is not an oneliner. Readability is actually very important in Ruby culture.
Ruby has an exception handling that is very similar to Python's, but the keywords seem to be blatantly stolen from Eiffel's Design By Contract. The transaction example from above could also be coded that way in Ruby:
t = start_transaction()
begin
do stuff with t
more stuff
rescue => e
puts "Caught an exception: #{e}"
ensure
t.end_transaction
end
I don't think that Ruby has a problem wth "non-alphanumeric" characters - it uses them very wisely, actually. I remember that Python uses lots of __foo__ and """bar""" - that really makes me feel uncomfortable when I have to read Python code!
f(x) = O(g(x)) as x approaches infinity means that
lim_x -> infinity abs(f(x)/g(x)) = c, where c is constant.
So it's bullshit to write something like O(2)
because you can multiply the c with 2 and you
would get another constant. Those functions
would thus belong to the same class of
asymptotic behaviour: O(1).
Yeah, I probably was on of them:
fake_user_agent Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)
This is much better readable than Java's anonymous inner classes trick:
...
add_listener do
end
Java also forces you to declare variables from the outer environment as final if you want to use them
in your method. So it's NOT possible to do something like that in Java:
called = 0
add_listener do
called += 1
puts "Called " + called + " times."
end
But java is also inconsistent in this respect because at the same time it's possible to work around this arbitrary limitation:
class IntCollection {
private int[] collection = null;
IntCollection(int ary[]) {
collection = ary;
}
public void each(Runnable block) {
for (int i = 0; i < collection.length; i++) { block.run(); }
}
}
class foo {
public static void main(String args[]) {
int[] ary = new int[10];
for (int i = 0; i < 10; i++) { ary[i] = i; }
IntCollection col = new IntCollection(ary);
final int count[] = new int[1];
col.each(new Runnable() {
public void run() { count[0]++; }
});
System.out.println("Counted " + count[0] + " elements.");
}
}
Only God knows why the Java language designers made such an obscure decision.
I'm not sure: a Proc object is a closure and some memory most be allocated for the environment. In a block it's easy because the environment is always the current environment.
Easy. Hashes have "=>"; blocks don't. :)
Not necasserily, {:a,1,:b,2} is also possible and blocks and hashes could also include hashes. One has really to look into the parser source to find out if that's so easy. And then it's necessary to convince Matz which isn't easy either (and this is a good thing I'd say). I think Perl has grown to be such an ugly beast because too much strange, inconsistent and unecessary syntax has been included. I'm not too optimistic that Perl6 does a better job here.
I worked in one shop where the style was to initial everything (e.g. identifiers of the form MQR.____) "to avoid name conflicts" and "so you always know who to talk to if it's broken"!
LOL! That's code ownership! And I suppose people still were cursing programmers that have left the company several years ago.
Matz held a talk on his intentions at OSCON (and it's fun to read) named
The Power and Philosophy of Ruby or How to create Babel-17.