Re:Just why did people start using Python anyway?
by davidw on Thursday October 09, 2008 @03:05AM
(#327581)
I started using Python in 1999, because I was tired of Perl's weirdness and looking for something new. I don't use it much these days, but still have a lot of respect for it.
[ Parent
| on HN ]
Re:Just why did people start using Python anyway?
by prakash on Thursday October 09, 2008 @07:10AM
(#327695)
what do you use these days?
Re:Just why did people start using Python anyway?
by davidw on Thursday October 09, 2008 @07:41AM
(#327714)
I got more involved with Tcl over time ( http://tcl.apache.org/ and some other stuff) and over the past couple of years have been moving towards Ruby for most of my scripting/web needs.
Re:Just why did people start using Python anyway?
by hugh on Thursday October 09, 2008 @09:28AM
(#327785)
Wait, you couldn't stand the weirdness of perl, but you like Tcl?
All I can remember about Tcl from my months of using it is the ugly, ugly loops:
for {set i 1} { $i <= 100 } { incr i } {
puts "Well, that wasn't ugly syntax!"
}
Incidentally, Fortran, for all its other ugliness, has the best for loop I know: do i = 1, 100
write(*,*) "Hooray, Fortran!"
enddo
Re:Just why did people start using Python anyway?
by davidw on Thursday October 09, 2008 @10:56AM
(#327870)
Tcl is extremely straightforward once you figure it out:
http://antirez.com/articoli/tclmisunderstood.html
'for' is a command that takes 4 arguments:
{set i 1} - eval'ed once at start time.
{ $i <= 100 } - an expression that is checked each time to determine whether to continue
{ incr i } - eval'ed each time
{ ... the rest ... } the body is eval'ed each time.
Everything in Tcl is like that - it's extremely easy to figure out and there are no surprises. It's also extremely easy to implement. Here's Hecl's for loop: case FOR:
/* The 'for' command. */
/* start */
interp.eval(argv[1]);
/* test */
while (Thing.isTrue(interp.eval(argv[2]))) {
try {
/* body */
interp.eval(argv[4]);
} catch (HeclException e) {
if (e.code.equals(HeclException.BREAK)) {
break;
} else if (e.code.equals(HeclException.CONTINUE)) {
} else {
throw e;
}
}
/* next */
interp.eval(argv[3]);
}
break;
Re:Just why did people start using Python anyway?
by nuclear_eclipse on Thursday October 09, 2008 @10:48AM
(#327859)
> Incidentally, Fortran, for all its other ugliness, has the best for loop I know:
How is that better than Python?
for i in range( 1, 100 ):
print "Python!"
Re:Just why did people start using Python anyway?
by abstractbill on Thursday October 09, 2008 @11:20AM
(#327889)
That's not a good idiom, because it only allows you to loop over small ranges:
>>> for i in range(1000000000):
... print i
...
python2.4(1261) malloc: *** vm_allocate(size=4000002048) failed (error code=3)
python2.4(1261) malloc: *** error: can't allocate region
python2.4(1261) malloc: *** set a breakpoint in szone_error to debug
Traceback (most recent call last):
File "<stdin>", line 1, in ?
MemoryError
Why attempt to allocate such a large list when you just want to do something several times?
Re:Just why did people start using Python anyway?
by oofoe on Thursday October 09, 2008 @12:33PM
(#327965)
for i in xrange(1000000000): print i
xrange() addresses the problem you describe and has been in Python since, like, forever. However, range() is nicer for learning the language, since it's easy to see how it composes into a list.
Re:Just why did people start using Python anyway?
by abstractbill on Thursday October 09, 2008 @12:41PM
(#327977)
Yes, I know. It's just bad that people are taught one way of iterating, and then may or may not learn the right way at some later time.
Re:Just why did people start using Python anyway?
by davidw on Thursday October 09, 2008 @10:59AM
(#327873)
Ruby's nice and compact too:
(1..100).each do
puts "Ruby"
end
Re:Just why did people start using Python anyway?
by qwph on Thursday October 09, 2008 @02:01PM
(#328074)
Maybe it's just me, but I like doing it this way in Ruby:
100.times { puts "Ruby" }
Not that there's anything wrong with your approach, but I just like the way that my code reads almost like English.
Re:Just why did people start using Python anyway?
by hugh on Thursday October 09, 2008 @02:40PM
(#328112)
Eleven characters! Beats Fortran by four. We have a winner!
(Counting only the loop-related characters, leaving out whitespace.)
Unless anyone has a shorter way of doing something one hundred times?
Re:Just why did people start using Python anyway?
by davidw on Thursday October 09, 2008 @02:44PM
(#328120)
I think if you want to talk about advantages though, with Fortran you're going to want to talk about the speed, not the brevity. Ruby is quite poky by comparison.
Re:Just why did people start using Python anyway?
by hugh on Thursday October 09, 2008 @03:59PM
(#328192)
Oh, for sure, but I'd hate to get drawn into the world's Nth general discussion of the advantages and disadvantages of programming languages. That would be dull.
Re:Just why did people start using Python anyway?
by davidw on Thursday October 09, 2008 @04:18PM
(#328209)
Actually, compared to batty discussions of economics or "politics!!!!!!", it's kind of soothing.