Computer Science Canada

Crush the python!

Author:  Insectoid [ Tue Jun 16, 2009 12:14 pm ]
Post subject:  Crush the python!

Posted Image, might have been reduced in size. Click Image to view fullscreen.

Author:  BigBear [ Tue Jun 16, 2009 4:50 pm ]
Post subject:  Re: Crush the python!

But Python received the Linux New Media Award in the category Best Open Source Programming Language.
Source

Author:  DtY [ Tue Jun 16, 2009 6:27 pm ]
Post subject:  Re: Crush the python!

BigBear @ Tue Jun 16, 2009 4:50 pm wrote:
But Python received the Linux New Media Award in the category Best Open Source Programming Language.
Source

Don't forget that python comes with libraries to do anything you could possibly ever want to do.

(Except pygame)

Author:  Shah-Cuber [ Tue Jun 16, 2009 6:31 pm ]
Post subject:  Re: Crush the python!

As a python programmer (mainly), I strongly disagree with this ...
Python FTW!

Author:  Insectoid [ Tue Jun 16, 2009 7:14 pm ]
Post subject:  RE:Crush the python!

Lol, I saw this while looking up that picture of uncle sam pointing at the reader. Just had to share it. Plus, I use Ruby, so while I don't think python sucks, python sucks compared to ruby.

Author:  DtY [ Wed Jun 17, 2009 11:34 am ]
Post subject:  Re: RE:Crush the python!

insectoid @ Tue Jun 16, 2009 7:14 pm wrote:
Lol, I saw this while looking up that picture of uncle sam pointing at the reader. Just had to share it. Plus, I use Ruby, so while I don't think python sucks, python sucks compared to ruby.

Ruby does have much nicer syntax. I think the only reason Ruby is a better language is that you can attach new methods to pre-existing classes. If python had that, I think I would have no reason to continue using Ruby.

[edit] And the method names, like:
Ruby:
class Something
def *(other)
self * other
end
end

Is much nicer looking than:
Python:
class Something:
    def __mul__(a,b):
        return a*b

Author:  Alexmula [ Wed Jun 17, 2009 2:08 pm ]
Post subject:  Re: Crush the python!

leave python alone ! Evil or Very Mad Laughing

Author:  andrew. [ Wed Jun 17, 2009 4:12 pm ]
Post subject:  RE:Crush the python!

I don't have much experience with Ruby, but I think that Python is a great language in general.

Author:  Dan [ Wed Jun 17, 2009 4:30 pm ]
Post subject:  Re: RE:Crush the python!

DtY @ 17th June 2009, 11:34 am wrote:
I think the only reason Ruby is a better language is that you can attach new methods to pre-existing classes. If python had that, I think I would have no reason to continue using Ruby.


Dos'nt every OOP langue have that threw inheritence? (Make a child class with the new method).

If you mean dynamically then thats posible too:

Python:

class foo:
   pass
   
bar = foo()

def new_method(self):
   print "Hello World"
   
foo.method = new_method

bar.method()

Author:  rdrake [ Wed Jun 17, 2009 4:55 pm ]
Post subject:  RE:Crush the python!

I think he means that you can attach and even replace methods from existing classes without needing inheritance.

Hell, you can add methods to even sealed classes in C# if you wanted to.

Author:  DtY [ Wed Jun 17, 2009 4:55 pm ]
Post subject:  RE:Crush the python!

Oh wow, I never thought of that. That's awesome!
It doesn't seem to work for builtin types though, which is a shame.

Python:
>>> def inc(self):
...     self+=1
...
>>> int
<type 'int'>
>>> int.inc = inc
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't set attributes of built-in/extension type 'int'

Author:  rizzix [ Wed Jun 17, 2009 6:58 pm ]
Post subject:  Re: RE:Crush the python!

rdrake @ Wed Jun 17, 2009 4:55 pm wrote:
I think he means that you can attach and even replace methods from existing classes without needing inheritance.

Hell, you can add methods to even sealed classes in C# if you wanted to.


A seemingly powerful but dangerous feature, since you've changed the semantics of a class without formally declaring to do so. But then again, Ruby is not strictly typed.

Author:  rdrake [ Wed Jun 17, 2009 10:15 pm ]
Post subject:  RE:Crush the python!

You can do funny things.

Ruby:
rdrake@HEXLEY:~$ irb
irb(main):001:0> class Fixnum
irb(main):002:1>   def to_s
irb(main):003:2>     "42"
irb(main):004:2>   end
irb(main):005:1> end
=> nil
irb(main):006:42>

Author:  Zeroth [ Sat Jun 20, 2009 11:16 am ]
Post subject:  Re: Crush the python!

Actually, thats only CPython for which that is true. Its not part of the python specification. Its only true for a specific interpreter.
code:

Jython 2.2.1 on java1.6.0_0
Type "copyright", "credits" or "license" for more information.
>>> dict
<type 'dict'>
>>> dict.test = lambda x: '42'
>>> dict.test()
Traceback (innermost last):
  File "<console>", line 1, in ?
TypeError: unbound method <lambda>() must be called with dict instance as first argument (got nothing instead)
>>> d=dict()
>>> d.test
<method dict.<lambda> of dict instance 1>
>>> d.test()
'42'
>>>


Now, as to the special method names, Python has a philosophy of using as few non-alphanumeric symbols as possible, where logical. They only use symbols for math, periods, commas, colons, semi-colons, brackets, etc. Besides, how would you differentiate in Ruby the difference between right multiplication, left multiplication, and normal multiplication? Python lets you define all three, where the left and right versions of multiply deal with situations where the other object doesn't have a multiply overload.

Author:  DtY [ Sat Jun 20, 2009 11:51 am ]
Post subject:  RE:Crush the python!

Isn't CPython the python specification? Writing a python script that wont work in CPython is useless.

Author:  wtd [ Sat Jun 20, 2009 12:07 pm ]
Post subject:  RE:Crush the python!

When viewed from the mainstream "Java and C++ are what everyone uses" point of view, both Python and Ruby (along with others) are fantastic programming languages, and any differences in fantasticness between them are comparatively minor.

I think the real strength of both is meta programming. Compared to statically-typed, natively compiled languages neither has any sort of performance merit, so their real advantage lies in reducing the work of the programmer. For metaprogramming, I will say that I think Ruby currently has the advantage, given that there's no legacy of different types of classes, that the syntax is of a more free form, and I firmly believe blocks are nicer to work with than Python generators, regardless of the technical or philosophical merits of either.

Author:  Bobrobyn [ Sat Jun 20, 2009 2:30 pm ]
Post subject:  RE:Crush the python!

I prefer Rails over the web framework alternatives for Python (although apparently Django scales better than Rails). Python is also faster...but if speed is really a concern for what I'm coding, I'll likely just use C...I'm one of those strange people that love C. And if it's fast web stuff...I guess I'd bite the bullet and use PHP *sigh*

I love Ruby's syntax, but in all honesty, if I were teaching programming, I'd probably teach Python. Forced indentation plus all of it's features (and Pygame for the kids to make fun games with!) makes it a perfect learning language -- I think it'd be better than Turing or Ruby for this purpose.

When it comes down to it: I say learn both, and use whichever one you prefer. There's no need for one to "crush" the other. Both have fantastic communities. Smile

Edit: I almost made this a rant about fanboys, but decided against it Razz

Author:  DtY [ Sat Jun 20, 2009 3:23 pm ]
Post subject:  RE:Crush the python!

I think it'd be better, if you're teaching a non-layout language, and have a lesson on organization, indentation, and so forth, rather than teaching python because it forces good style.

Author:  Bobrobyn [ Sat Jun 20, 2009 7:00 pm ]
Post subject:  Re: RE:Crush the python!

DtY @ Sat Jun 20, 2009 4:23 pm wrote:
I think it'd be better, if you're teaching a non-layout language, and have a lesson on organization, indentation, and so forth, rather than teaching python because it forces good style.


I agree with the lesson part. I think having a lesson on the importance of good code style and organization (including indentation and commenting) is very important. However, I still think that the python enforcement of good style would be beneficial to learning new languages in the future. In the beginner CS courses at my uni, and even in higher level courses, I often see students code without proper style who ask for help. When I mention their code style, their reply is often "Oh yeah, I know...I'm going to clean it up a bit before handing it in". I then tell them that if they clean it up a bit, I'll help them...and they unhappily do it. Messy C code is not fun to look at.

I think that Python FORCING good style from the beginning would stop this from happening. It'll make code that looks good and is easier to read and debug from the moment the text editor is opened -- instead of a last minute thing to do if there's time. I love Ruby, and I think it would be a fantastic language to begin with, but Python wins when it comes to enforcing styling here. Ruby would be a much better language to get into when teaching object orientation, however, as it's pure OO...so going Python -> C -> Ruby or Java for OO -> whatever else...would be the way I'd think it should go.

(My personal opinion is that people should learn C, pointers, memory management, and about data structures (and ADT's) before they delve too far into object orientation. I've seen people have trouble with not-thinking in an OO way if they started with OO...but that's sorta out of the range of this topic Razz Sorry for getting too far out there, guys.)

Author:  Zeroth [ Sat Jun 20, 2009 9:40 pm ]
Post subject:  Re: RE:Crush the python!

DtY @ Sat Jun 20, 2009 8:51 am wrote:
Isn't CPython the python specification? Writing a python script that wont work in CPython is useless.


No, CPython is a reference implementation. Because of some of the limits of C, its very difficult to make it safe to set attributes on classes coded in C. If you're familiar with the C API, you'll understand, but it would honestly take too long to explain here. But, as I said, CPython is only a reference implementation. It is the most used implementation, but its still just one implementation. This is very different from a specification Wink.

Author:  DtY [ Sat Jun 20, 2009 9:50 pm ]
Post subject:  RE:Crush the python!

By C API do you mean the python API in C, or C in general? I don't know anything about the python api, but I know some C. I understand where it'd be hard to do that though.

What I meant though, was that python doesn't have any formal specification (does it?), whereas a language like javascript has some specifications it needs to follow to be standards complient. Since CPython is the implementation (like it's the original one, and I think, the only one until a few years ago) it's the specification (unless there's something written up I don't know about?)

Author:  Zeroth [ Sat Jun 20, 2009 10:49 pm ]
Post subject:  Re: Crush the python!

Uh... What about this: http://docs.python.org/reference/

I'd call that a specification...

Author:  DtY [ Sat Jun 20, 2009 11:47 pm ]
Post subject:  RE:Crush the python!

Ah, I guess it does.

Author:  Zeroth [ Sun Jun 21, 2009 11:14 am ]
Post subject:  Re: Crush the python!

But anyway, back on point. I personally feel that Ruby is too... lackadaisical. Its too loose in what it allows. This leads to about four or five different equally valid ways to do one simple task. Ruby was designed more to be more relaxed than Python, without any real grounding in good language design goals. Guido von Rossum had plenty of experience in language design, and how easy they were to learn. He was involved the development and testing of ABC, a language for non-programmers. He used that experience to design and develop Python. One of the key ideas of Python, is that readability is king. So the language works hard to keep things readable, using words instead of symbols, and providing the idea that there is usually one correct way to do something, rather than ten million ways in Ruby.

The freedom of Ruby appeals to some programmers, and repels others, like me. Programming so long in Python, I prefer beautiful code. It is possible to write beautiful code in any language, but in Ruby, the beautiful looking code ends up being the worst possible choice to make. I dislike ruby for that reason.

Author:  rdrake [ Sun Jun 21, 2009 12:53 pm ]
Post subject:  Re: Crush the python!

Zeroth @ Sun Jun 21, 2009 11:14 am wrote:
It is possible to write beautiful code in any language, but in Ruby, the beautiful looking code ends up being the worst possible choice to make. I dislike ruby for that reason.
Worst how? I find in Ruby if my code is not beautiful looking it is probably wrong.


: