Why Perl is better than Python
1
Name:
Anonymous
2012-06-02 13:53
typo = 0;
while (typo < 10): # timeout
typ0 = typo + 1
Compared to:
use strict;
my $typo = 0;
while ($typo < 10) {
$typ0 = $typo + 1 # will abort with error
}
2
Name:
Anonymous
2012-06-02 14:24
local function nope (_, k) error("undeclared `" .. k .. "'", 2) end
setmetatable(getfenv(1), { __index = nope, __newindex = nope })
local typo = 0
while typo < 10 do
typ0 = typo + 1
end
>local by default
>typos turn into new variables
>global by default
>catch all global assignments
like a boss
3
Name:
Anonymous
2012-06-02 14:33
>>1
Why do you have to ``use strict'', is Perl that shit?
4
Name:
Anonymous
2012-06-02 14:47
>>3
Because he neglected to mention that if he doesn't, perl has the exact same semantics as python in that case
5
Name:
Anonymous
2012-06-02 15:06
>>4
Yeah, but in your
toy language there is no "use strict" counterpart...
6
Name:
Anonymous
2012-06-02 15:19
>>5
My toy language is Haskell.
7
Name:
Anonymous
2012-06-02 16:50
8
Name:
Bernd
2012-06-02 17:03
#!/usr/bin/env ruby
typo = 0
while typo < 10 do
typo = typo + 1
end
9
Name:
Anonymous
2012-06-02 18:24
Haskell version:
module Main where
main = whSegmentation fault: Haskell can't do loops or variables!
10
Name:
Anonymous
2012-06-02 18:38
11
Name:
Anonymous
2012-06-02 19:42
enjoy your concept of 0 but true and your pathological language that cannot be unambiguously parsed
module EatMe where
main = do
typo <- newIORef 0
[0..9] `forM_` const (modifyIORef typo (+1))
12
Name:
Anonymous
2012-06-03 1:40
>>3
>>4
IMO "use strict;" should be the default, and you should have to actively decline the use of strict. More people would use strict that way.
All good perl programs start with "use strict;".
13
Name:
Anonymous
2012-06-03 1:51
(do ((typo 0))
((> typo 10))
(incf typ0))
UNDEFINED VARIABLE:
type0
14
Name:
Anonymous
2012-06-03 2:50
>>3
>>12
To be fair, it is not exactly required. It's not going to break your script if you omit it. It's more of a tool to keep you from writing shitty code. In that case, I agree with you that it should be on by default.
YEAH, BUT WHO DOESN'T use strict; THEIR CODE?
15
Name:
Anonymous
2012-06-03 2:55
>>13
At least the python interpreter doesn't give errors about variables you've never even talked about in your code.
16
Name:
Anonymous
2012-06-05 16:38
>>1
typo = 0
while typo < 10:
typ0 += 1 # NameError
Now go away.
Newer Posts