0353: "Python"

This forum is for the individual discussion thread that goes with each new comic.

Moderators: Moderators General, Prelates, Magistrates

UltramaticOrange
Posts: 45
Joined: Wed May 30, 2007 3:31 am UTC
Contact:

Re: "Python" discussion

Postby UltramaticOrange » Wed Dec 05, 2007 6:09 pm UTC

hotaru wrote:
UltramaticOrange wrote:Well, strictly speaking, if we're breaking into your place anyway, we don't need the root password. It's been a while since I've done it so I don't remember all the details, but you can stop grub/lilo from booting the os, tell it that the init script is "/bin/bash" (or in your case tsh or whatever else might be your favorite prompt) then unmount/mount key parts of the system (if I recall correctly, / and /proc). Viola. Full root access without a password. I should still have (poor) notes/bookmarks on how to do this correctly someplace at home. If I can reproduce the steps, I'll post them.

or you could just open the case, pull the hard drive out, pop it into an external enclosure, and change anything you want on it.


I thought of that, but didn't want to fall into the 'I encrypt my disks' trap.

edit: Although thinking about it a little harder, I guess I already did with the whole init=/bin/bash thing.
Image

Chainsaw Fencing Champ
Posts: 23
Joined: Wed Jul 18, 2007 3:31 pm UTC
Contact:

Re: "Python" discussion

Postby Chainsaw Fencing Champ » Wed Dec 05, 2007 6:50 pm UTC

tehmoth wrote:
Leliel wrote:I <3 python, but I could be biased because I went from using PERL

Perl is the language, perl the interpreter, there is no PERL

Hearing this, he was enlightened.

benjhayden
Posts: 3
Joined: Wed Dec 05, 2007 5:05 am UTC

Re: "Python" discussion

Postby benjhayden » Wed Dec 05, 2007 7:03 pm UTC

Pipian wrote:Seriously, can you define and implement methods in some random file and then mix them seamlessly into any Python class you choose without subclassing and almost implement multiple inheritance? Ruby can.**

Like this?

Code: Select all

# utils.py
def method(cls):
    def decorator(fun):
        setattr(cls, fun.__name__, fun)
        return fun
    return decorator

Code: Select all

# frob_method_of_socket.py
@method(socket._socketobject)
def frob(self):
    print "i'm a method of %s!" % self.__class__.__name__

User avatar
fortyseventeen
Ask for a lame title, receive a lame title
Posts: 88
Joined: Fri Mar 02, 2007 3:41 am UTC
Location: SLC, UT, USA
Contact:

Re: "Python" discussion

Postby fortyseventeen » Wed Dec 05, 2007 7:09 pm UTC

Why are we ignoring Ruby and comparing the two P's directly? They're pretty different from each other. Ruby is in the middle ground, or thereabouts.

tehmoth wrote:
++$_ wrote:Indeed. Who doesn't? (Well, maybe the people who developed Python don't, because they're religiously opposed to it.) Personally, I think @_ is a better idea than named arguments (although it would be nice to have both options).


Code: Select all

foo(one => 'a', two => 'b');
foo(two => 'x');

sub foo {
    my %parameters = (
      one => 'bar default',
      two => 'baz default',
      @_,
    );
    print "one $parameters{one} - two $parameters{two} \n";
}


Ruby does this by allowing the brackets to be left off of a hash that terminates an argument list, e.g render(text, :size => 14) has two arguments, the text and the hash {:size => 14}.

Code: Select all

class StoopidGooey
  @style = {:color => 0xFFFFFF, :size => 12}
 
  def render(thing, opts={})
    opts = @style.merge(opts)
    # ...
  end
 
  def style(opts)
    @style.merge!(opts)
  end
end


Works basically the same way when combined with optional arguments, but you can also take the option away. Interestingly, though, it appears that named arguments are coming in Ruby 2 as an alternative to this.
Quick, what's schfifty-five minus schfourteen-teen?

User avatar
fortyseventeen
Ask for a lame title, receive a lame title
Posts: 88
Joined: Fri Mar 02, 2007 3:41 am UTC
Location: SLC, UT, USA
Contact:

Re: "Python" discussion

Postby fortyseventeen » Wed Dec 05, 2007 7:40 pm UTC

Oops, didn't see this one:

benjhayden wrote:
Pipian wrote:Seriously, can you define and implement methods in some random file and then mix them seamlessly into any Python class you choose without subclassing and almost implement multiple inheritance? Ruby can.**

Like this?

Code: Select all

# utils.py
def method(cls):
    def decorator(fun):
        setattr(cls, fun.__name__, fun)
        return fun
    return decorator

Code: Select all

# frob_method_of_socket.py
@method(socket._socketobject)
def frob(self):
    print "i'm a method of %s!" % self.__class__.__name__


That's a little scary-looking...pardon my ignorance, but what is actually happening? Also not very encapsulated. When would you want to import a single method? I would just rely on normal inheritance, probably. Otherwise, I want to import a whole pack of methods at a time (Ruby):

Code: Select all

class SomeKindaList
  include Enumerable
 
  def each
    #...
  end
end


Now I can use my list as I would any other, with #map, #inject, #find, etc. Note that Enumerable only works for classes with #each. Mix-ins typically trust the programmer to provide one or more core methods that are built upon by the mixed-in module, so they're kinda like Java's interfaces (Collection, List), but don't force you to implement all of the convenience methods yourself (although you can override them if you want, for efficiency, etc.) or to put that added functionality in a separate util class. Enumerable is kind of like an abstract class (AbstractList), too, but it doesn't restrict the inheritance heirarchy. It's also not quite multiple inheritance, because only modules can be mixed in, which are not instantiable.

Yet, I'm interested in what cases true multiple inheritance would be more desirable. It seems to be more dangerous, though.
Quick, what's schfifty-five minus schfourteen-teen?

User avatar
rqm
Posts: 42
Joined: Wed Dec 05, 2007 7:30 pm UTC
Location: Mars
Contact:

Re: "Python" discussion

Postby rqm » Wed Dec 05, 2007 8:40 pm UTC

Count me on those who registered to comment about Python. Some people here are talking about whether Python is for those who don't want to learn programming or those who do. Well the thing about Python is that it's BOTH programmaticaly powerfull yet uncomplicated, i say that Python stole the "Principle of least surprise" from under Ruby's feet.

About monkeypatching a class of course we can, this is just one way to do it, with this one you don't even need to know what class you are pathing:

Code: Select all

>>> class Ball:
   def __init__(self, color):
      self.color = color
>>> ball = Ball('red')
>>> def change_color(self, color):
   self.color = color
>>> ball.__class__.change_color = change_color
>>> ball.change_color('green')
>>> ball.color
'green'


Of course, this example shows a redundant method because in Python you can access properties directly whereas in Ruby you have to write an accessor. True, there are shortcuts to write accessors but they cover the fact that properties shouldn't be private by default. And rubyists, don't tell me public properties are dangerous while guerrilla patching your built-in classes.

Seriously half of Ruby's features are patch work that cover for the problems the other half of features cause.
Last edited by rqm on Wed Dec 05, 2007 8:43 pm UTC, edited 1 time in total.

User avatar
segmentation fault
Posts: 1770
Joined: Wed Dec 05, 2007 4:10 pm UTC
Location: Nu Jersey
Contact:

Re: "Python" discussion

Postby segmentation fault » Wed Dec 05, 2007 8:43 pm UTC

what is guerilla patching?

rqm wrote:Seriously half of Ruby's features are patch work that cover for the problems the other half of features cause.


i disagree completely.
people are like LDL cholesterol for the internet

Pxtl
Posts: 44
Joined: Thu Sep 20, 2007 1:12 pm UTC

Re: "Python" discussion

Postby Pxtl » Wed Dec 05, 2007 8:56 pm UTC

Ahh, Python. I love the language. Where most programming languages start out illegible and proceed to make more sense as you work with them more and more, Python does the opposite. It's intuitive, compilable pseudo-code, which is great until you realize that everyone has a slightly different idea of what's "intuitive" and basically you have to read Guido's mind.

That being said, I can do some utterly twisted things in it.

User avatar
segmentation fault
Posts: 1770
Joined: Wed Dec 05, 2007 4:10 pm UTC
Location: Nu Jersey
Contact:

Re: "Python" discussion

Postby segmentation fault » Wed Dec 05, 2007 9:09 pm UTC

Pxtl wrote:That being said, I can do some utterly twisted things in it.


i see what you did there.
people are like LDL cholesterol for the internet

User avatar
rqm
Posts: 42
Joined: Wed Dec 05, 2007 7:30 pm UTC
Location: Mars
Contact:

Re: "Python" discussion

Postby rqm » Wed Dec 05, 2007 9:20 pm UTC

segmentation fault wrote:what is guerilla patching?

rqm wrote:Seriously half of Ruby's features are patch work that cover for the problems the other half of features cause.


i disagree completely.


Guerilla patching is a reference to the problem of multiple modules patching the same classes at the same time, Guerrilla -> Gorilla -> Monkey.

Of course you disagree, and I'm not going to go deep into languague bashing, just a sample, one of my favorites for its length is this chain.

Ruby introduces a cute datatype, the :symbol which is like a string but lighter and unique, which is a patch over three problems, that ruby strings are not cached, that ruby strings are mutable and worse that bare words are not suitable to pass objects around. And bare words are not suitable to pass objects around because they are always asumed to be method calls which is a by product of the optional parenthesis feature of 'functions' (methods) which in turn means that not only you cant refer to functions by name but you can't refer to methods of classes by name either, so another notation had to be invented (someclass#somemethod) and so you usualy extract methods by calling yet another method and passing the name of the method you want as a symbol, all of this causes so much trouble that you rather forget about methods altogether and prefer to pass "proc" objects instead, that are actually wrappers around methods because methods, like blocks, are not objects which means that the "Every thing is an object in Ruby" is said with a wink.

And that's just one (chain of) example of what i'm talking about.
I'm not saying Ruby is useless, just that Python is better but of course YM*W*V.
Last edited by rqm on Wed Dec 05, 2007 9:27 pm UTC, edited 1 time in total.

User avatar
OmegaLord
LXIX
Posts: 281
Joined: Sat Sep 01, 2007 10:33 pm UTC
Contact:

Re: "Python" discussion

Postby OmegaLord » Wed Dec 05, 2007 9:25 pm UTC

Basic ftw. Not even real BASIC. Liberty BASIC. I have a semi-workable 1337 translator, too.
Spoiler:

Code: Select all

input "enter |_337 ";var$
cls
num = len(var$)
 i = 1
 num2  = num
while i < (num + 1)
[spleen]
   token1$ =  mid$(var$ ,i , 1)
 token2$ =  mid$(var$ ,i , 2)
  token3$ =  mid$(var$ ,i , 3)
    token4$ =  mid$(var$ ,i , 4)
   i = i + 1
   lenv = len(varx$)
   if token3$ = "teh" then
    varx$ = varx$ + "the"
   i = i + 2
   end if
    if token1$ = "8" then varx$ = varx$+"b"
    if token1$ = "1" then varx$ = varx$+"i"
   if token1$ = " " then varx$ = varx$ + " "
   if token2$ = "|2" then
    varx$ = varx$ + "r"
     i = i + 1
   end if
      if token1$ = "2" then varx$ = varx$ + "too"
      if token4$ = "\/\/" then
    varx$ = varx$ + "w"
     i = i + 3
   end if
         if token4$ = "|\/|" then
    varx$ = varx$ + "m"
     i = i + 3
   end if

   if token2$ = "|_" then
    varx$ = varx$ + "l"
             i = i + 1
   end if
    if token2$ = "|)" then
    varx$ = varx$ + "d"
             i = i + 1
   end if
   if token3$ = "|_|" then
    varx$ = varx$ + "u"
     i = i + 2
   end if
   if token2$ = "\/" then
    varx$ = varx$ + "v"
         i = i + 1
   end if
      if token2$ = "|<" then
    varx$ = varx$ + "k"
         i = i + 1
   end if
   if token3$ = "|-|" then
    varx$ = varx$ + "h"
     i = i + 2
   end if
      if token3$ = "|\|" then
    varx$ = varx$ + "n"
     i = i + 2
   end if
   if token1$ = "7" then varx$ = varx$ + "t"
   if token1$ = "+" then varx$ = varx$ + "t"
   if token1$ = "4" then varx$ = varx$ + "a"
    if token1$ = "#" then varx$ = varx$ + "f"
     if token1$ = "6" then varx$ = varx$ + "g"
      if token1$ = "3" then varx$ = varx$ + "e"
      if token1$ = "0" then varx$ = varx$ + "o"
      if token1$ = "5" then varx$ = varx$ + "s"
if len(varx$) = lenv then varx$ = varx$ + token1$
wend
num = len(varx$)
 i = 1
 num2  = num
while i < (num + 1)
   token$ =  word$(varx$ ,i , 1)
   i = i + 1
   lenv = len(varx2$)
   if lower$(token$) = "teh" then varx2$ = varx2$ + "the"
if lenv = len(varx2$) then varx2$ = varx2$ + token$
   wend
    print lower$(varx2$)
    end



OH YES.
So what do you guys know about *glances down at sheet* the kingdoms of orgasms
but I just don't see why someone would tape themselves together.
Bear Police wrote:I got Ready to Die today. Took me too long. Great record.

Ursus
Posts: 9
Joined: Mon Sep 04, 2006 11:30 pm UTC

Re: "Python" discussion

Postby Ursus » Wed Dec 05, 2007 9:50 pm UTC

When you need performance in your string manipulations, you'll come crawling back . . .

I can definitely see the advantage, however, of a language designed to make most programming tasks easy. I still prefer being able to do anything. Then again, I code for a living.

:-D

User avatar
segmentation fault
Posts: 1770
Joined: Wed Dec 05, 2007 4:10 pm UTC
Location: Nu Jersey
Contact:

Re: "Python" discussion

Postby segmentation fault » Wed Dec 05, 2007 9:50 pm UTC

rqm, thats like saying "mutable" is a patch over const methods not being able to change the "this" object, therefore c++ is a giant ball of hacks.

instead of looking at it like its a problem, just say "in ruby, strings are used for one thing, symbols for something else." specifically:

1) if the contents of the object are important, use a string.
2) if the identity of the object is important, use a symbol.

it's just providing similar solutions to different problems.
people are like LDL cholesterol for the internet

User avatar
Kaletécho
Posts: 36
Joined: Sat Dec 01, 2007 3:03 am UTC
Contact:

Re: "Python" discussion

Postby Kaletécho » Wed Dec 05, 2007 9:52 pm UTC

Is now a bad time to express my newfound unconditional passion for you, Mr. Munroe?
Spoiler:
Fossa wrote:[The other thread] is clearly about marital arts which, to my understanding, are a lot more painful and involve less grappling than you'd think...

Cheese wrote:I would say "I am a douche", but then someone would sig it.

User avatar
Jach
Posts: 167
Joined: Sat May 05, 2007 8:38 pm UTC
Contact:

Re: "Python" discussion

Postby Jach » Wed Dec 05, 2007 9:57 pm UTC

Hooray, another Python lover. Python is great, after all. Plus the Zen actually makes sense. (import this)
I love reading quotes.

Doug-W
Posts: 2
Joined: Tue Aug 07, 2007 7:56 pm UTC

Re: "Python" discussion

Postby Doug-W » Wed Dec 05, 2007 10:09 pm UTC

Randall should look closer at Ruby then. My take was always that Ruby was made by a bunch of Perl hackers who looked at Python and said, "We can do that better." and then did so.

Ironically today is the first time I'm scripting in over a year as I try to figure out how to regex match utf16 and non-UNICODE ascii together.

User avatar
muteKi
Angry is too weak a term. Try "Fluffy".
Posts: 372
Joined: Tue Dec 19, 2006 4:02 am UTC
Location: William and Mary, Williamsburg, VA

Re: "Python" discussion

Postby muteKi » Wed Dec 05, 2007 10:13 pm UTC

LDJosh wrote:There are over 30 programming languages on my resume.
No I didn't just list languages either. these are languages I have actually learned & coded in.

Python & Perl have their different uses. It's comparing apples & oranges. They're both fruit, but you put apples in a pie, and you mix orange juice with vodka, ok? You could put oranges in a pie and put vodka in apple juice, but then you're just a damn idiot.

Python is for small apps. Perl is for shell scripting.


Not into Appletinis, eh?
Image

User avatar
rqm
Posts: 42
Joined: Wed Dec 05, 2007 7:30 pm UTC
Location: Mars
Contact:

Re: "Python" discussion

Postby rqm » Wed Dec 05, 2007 10:37 pm UTC

Mutability is great, I only have a problem with mutability in value-ish classes like strings, dates, colors, paths, urls, temperatures or anything that represents specific values you wouldn't suggest making integers mutable in Ruby would'ya? But that's not the real problem :symbols aim to fix.

instead of looking at it like its a problem, just say "in ruby, strings are used for one thing, symbols for something else." specifically:

1) if the contents of the object are important, use a string.
2) if the identity of the object is important, use a symbol.

it's just providing similar solutions to different problems.


Neither of which problems are one that made :symbols a practical necessity in Ruby, yet even if that was the case, isn't one solution fixing two problems more elegant that learning two different datatypes and their respective methods?

Both languages can do pretty much the same but Ruby is always introducing new concepts new keywords and new punctuations, whereas Python does a lot conceptual re use, at the price of some verbosity (Python's init is specially tedious and one of the few justifications for macros I can find in the language).

In the end is a matter of taste. Neither language is Visual Basic after all, isn't that wonderful.

User avatar
lysandra
Posts: 99
Joined: Fri Nov 09, 2007 6:36 am UTC
Contact:

Re: "Python" discussion

Postby lysandra » Wed Dec 05, 2007 11:15 pm UTC

http://heather.cs.ucdavis.edu/~matloff/python.html

If anyone is looking for another intro to python, here's one from one of my classes.

russianspy1234
Posts: 51
Joined: Mon Sep 10, 2007 4:43 am UTC

Re: "Python" discussion

Postby russianspy1234 » Wed Dec 05, 2007 11:18 pm UTC

Link removed.

Pipian
Posts: 3
Joined: Wed Dec 05, 2007 6:57 am UTC

Re: "Python" discussion

Postby Pipian » Wed Dec 05, 2007 11:32 pm UTC

benjhayden wrote:
Pipian wrote:Seriously, can you define and implement methods in some random file and then mix them seamlessly into any Python class you choose without subclassing and almost implement multiple inheritance? Ruby can.**

Like this?

Code: Select all

# utils.py
def method(cls):
    def decorator(fun):
        setattr(cls, fun.__name__, fun)
        return fun
    return decorator

Code: Select all

# frob_method_of_socket.py
@method(socket._socketobject)
def frob(self):
    print "i'm a method of %s!" % self.__class__.__name__


Nifty. Makes sense, given how Python works, even if it is a little bit more awkward than Ruby's module syntax.

User avatar
RAPTORATTACK!!!
Posts: 72
Joined: Sat Sep 30, 2006 8:48 pm UTC
Location: Aroundabouts boston.

Re: "Python" discussion

Postby RAPTORATTACK!!! » Wed Dec 05, 2007 11:40 pm UTC

Wonderful!

As of a few months ago I was working on learning python to make a 3d game to use the various models i've made, but since my programming knowledge begins with html, and ends about 20-30 pages into a 3 inch thick c++ book, its been a bit difficult. fun though. I've been waiting for somthing like this.

couple this with a softer world: import (love)
Image
Team 246 OVERCLOCKED!

Ronfar
Posts: 132
Joined: Mon Dec 04, 2006 6:04 am UTC

Re: "Python" discussion

Postby Ronfar » Wed Dec 05, 2007 11:48 pm UTC

My first programming language was GWBasic, if that even counts. Line numbers and GOTOs for everything... yuck.

My second was Perl, which I learned on the job, using the Camel Book and an Internet connection. I like Perl.

My third was FORTRAN, which, until recently, was the language used in the "Introduction to Computers for Engineers" course required for all Rutgers engineering students. I have since forgotten all of it.

My fourth was C++, which I also learned at Rutgers. It was okay, but I like Perl better.
- Doug

tialaramex
Posts: 9
Joined: Mon May 07, 2007 4:16 pm UTC

Re: "Python" discussion

Postby tialaramex » Wed Dec 05, 2007 11:59 pm UTC

Firstly, to chime in late on the "Python is a bad place to start" stuff...

Computer programming is about abstractions. The problem is that the abstractions leak. So to be any good it's not enough to rely on the abstraction, you need to understand all the stuff that's being abstracted away, so that when your abstraction leaks you understand what's going on. Otherwise you waste a lot of time on unexplained phenomena because you don't have the necessary context. This doesn't make the abstraction worthless (ie it doesn't mean you should use 68000 series assembler to write a script for counting the unique referer URLs in a webserver log) but it does mean sometimes knowing Python isn't enough to understand what's wrong with your Python program.

That's why I write a lot of code in C, a little Perl, a few shells scripts, some Java, and even occasionally some Python. But mostly C. Because mostly I don't have the sort of problems you can solve with Python, the same way Inspector Morse rarely gets asked to investigate the sort of murders you can solve by following the trail of bloody footprints. If you could solve the problem with Python, a Python programmer would already have done it, and probably one tried, it made a big mess and now they've called for me.

Anyway, I had another beef with Python. It's 2007. Python, unlike say C, claims to be a modern language written by people who think nothing of transparently handling integers and fractions rather than expecting the programmer to manually decide which they want and then stick to that. So, why is its Unicode support so abysmal? Perl screwed this up in a uniquely Perl way, with dozens of separate parameters that affect the Unicode behaviour, options to secretly encode things as UTF-8 or not, and so on. I can imagine that in a few more years everyone's Perl will be configured to behave in a rational way using UTF-8 everywhere and the die-hards will stick with whatever old version they have hand rolled that still uses ISO-8859-1. But Python seems to have very carefully tied itself up in knots, in a way that's not reflected anywhere else in the language. To the extent that they chose UCS-2 as their internal representation, even though it was already obsolete when they did so. UCS-2 is really, really stupid. Head in the microwave stupid. That's like deciding in 1996 that you're going to make your next home PC an 8-bit machine. "Oh, I'm sure this craze for 16-bit and 32-bit computers will blow over soon".

IIMarckus
Posts: 5
Joined: Thu Dec 06, 2007 12:03 am UTC

Re: "Python" discussion

Postby IIMarckus » Thu Dec 06, 2007 12:07 am UTC

Python? Pfft. Assembly is where it's at.

yaPete
Posts: 31
Joined: Wed Nov 28, 2007 8:25 am UTC

Re: "Python" discussion

Postby yaPete » Thu Dec 06, 2007 1:05 am UTC

UltramaticOrange wrote:one of my professors back in my college days left one of his perl scripts on the department server chmod'd to 777 so I added 200 blank lines and had it write an alias command in his .bashrc file to change su to a program that gave the same output as the actual su command then emailed me whatever was typed in as a password, claimed that it wasn't typed correctly, removed the alias then ran the actual su program. Sadly, he never ran the perl script.


Well, that's one explanation for you never getting the email. I can think of at least three more :-)

Pete

kwan3217
Posts: 27
Joined: Wed Jul 11, 2007 1:44 am UTC
Location: Sun-synchronous Earth Orbit

Re: "Python" discussion

Postby kwan3217 » Thu Dec 06, 2007 1:20 am UTC

The only feature I know about Python (and Ruby, for that matter) is the "brainwash" function. Seriously, everywhere you go on the net, its "Try python, you'll like it, I promise!" "Everyone else is doing it!" "Join the cult!"

Every language sucks. I happen to prefer Java at the moment, but it has its own flaws (sometimes you really do need multiple inheritance and operator overloading). I'm just happy with any programming system that is Turing complete.
Some people look at what is, and ask "why?"
Some people dream about what isn't, and ask "why not?"
I think about it for a while, then say "Oh, that's why not."

User avatar
r1chard
Posts: 281
Joined: Thu Dec 06, 2007 2:17 am UTC
Location: Melbourne, AU
Contact:

Re: "Python" discussion

Postby r1chard » Thu Dec 06, 2007 2:21 am UTC

Great comic, I laughed :)



And people, there's a separate Wars forum for your languages debate.

Go there!

Sheesh.

User avatar
distributed
Posts: 5
Joined: Thu Aug 02, 2007 3:05 am UTC
Location: Arrakis

Re: "Python" discussion

Postby distributed » Thu Dec 06, 2007 2:27 am UTC

Perl, I'm leaving you.

I guess now would be the right time to say - "Another one bites the dust!!" :D
siggy baby

Workaphobia
Posts: 121
Joined: Thu Jan 25, 2007 12:21 am UTC

Re: "Python" discussion

Postby Workaphobia » Thu Dec 06, 2007 4:29 am UTC

Come on, can't I read xkcd for just one month without being reminded how awesome Python is and how badly I need to learn it? I mean, it is bad enough that a friend of mine implemented an op sys homework assignment with an order of magnitude fewer lines of code, and that I just spent many hours this week finding stupid buffer based mistakes in a final project written in C, and that I have absolutely no time at the moment to give to learning a new language, but what am I to do when xkcd is mocking me so?
Evidently, the key to understanding recursion is to begin by understanding recursion.

The rest is easy.

User avatar
tiny_sparks
Posts: 6
Joined: Wed Dec 20, 2006 6:03 am UTC

Re: "Python" discussion

Postby tiny_sparks » Thu Dec 06, 2007 4:56 am UTC

Sorry, I just wanted to jump on the bandwagon and say that PYTHON IS AMAZING.

I learned Java a few years back, I think it's all right. :\

A few months ago, I sat in on a friend's CompSci lecture because I was bored. The TA was going over the differences between Java and Python. He opened up the Java code for the class's last turned-in assignment, and went step-by-step on how to convert it to Python.

It was a small program, only 80-something lines. But the TA got it down to about 17 lines of Python code, right before my very eyes. I so wish I had the code with me to show you, because it was MAGICAL.

Dsarker
Posts: 4
Joined: Fri Aug 17, 2007 1:30 pm UTC

Re: "Python" discussion

Postby Dsarker » Thu Dec 06, 2007 6:08 am UTC

Yippee! I have supported Python for years!Now I am proved right! :D :mrgreen: :lol: :) :D

User avatar
Framling
Posts: 62
Joined: Sat Dec 02, 2006 6:58 am UTC

Re: "Python" discussion

Postby Framling » Thu Dec 06, 2007 9:12 am UTC

Arg, one-line Hello Worlds drive me nuts. That doesn't contain any useful information! All I know now is how to output text, I don't know anything about the structure of a typical program.

I hit this over and over when I was trying to learn Foxpro. Hello World was something like

Code: Select all

?Hello World!


Awesome, I still don't know any Foxpro, thanks!
your = belonging to you
you're = you are
their = belonging to them
they're = they are
there = not here

User avatar
Wheat
Posts: 4
Joined: Thu Dec 06, 2007 4:05 am UTC
Location: Vancouver, BC

Re: "Python" discussion

Postby Wheat » Thu Dec 06, 2007 9:15 am UTC

rqm wrote:Guerilla patching is a reference to the problem of multiple modules patching the same classes at the same time, Guerrilla -> Gorilla -> Monkey.


No, the term guerilla patch and monkey patch originated in Zope. Guerilla Patch came first, and referred to the fact that you can install someone elses package, and it can "patch" your own code without you knowing it. This was misheard as "Gorilla Patch" and so the term "Monkey Patch" was put forth as a kinder, gentler patch.

http://en.wikipedia.org/wiki/Monkey_patch

User avatar
Wheat
Posts: 4
Joined: Thu Dec 06, 2007 4:05 am UTC
Location: Vancouver, BC

Re: "Python" discussion

Postby Wheat » Thu Dec 06, 2007 9:48 am UTC

When would you want to import a single method? I would just rely on normal inheritance, probably. Otherwise, I want to import a whole pack of methods at a time (Ruby):

Code: Select all

class SomeKindaList
  include Enumerable
 
  def each
    #...
  end
end


Now I can use my list as I would any other, with #map, #inject, #find, etc. Note that Enumerable only works for classes with #each. Mix-ins typically trust the programmer to provide one or more core methods that are built upon by the mixed-in module, so they're kinda like Java's interfaces (Collection, List), but don't force you to implement all of the convenience methods yourself (although you can override them if you want, for efficiency, etc.) or to put that added functionality in a separate util class. Enumerable is kind of like an abstract class (AbstractList), too, but it doesn't restrict the inheritance heirarchy. It's also not quite multiple inheritance, because only modules can be mixed in, which are not instantiable.



You'd want to import just a single method when you are importing from
two modules that both have something with the same name and they are names
are clashing with each other. In Python you can do:

Code: Select all

from module import *


And pull in the whole namespace if you like. This is considered bad form
in a larger application though, where the style is to import one name
per line. Yes, you get a large block of imports, but it's really easy to
search for a name and see *exactly* where it's coming from.

Python has mix-ins as well (and they are also called mix-ins). They are just Classes that are only intended to be added to other Classes. This does the same thing as the Ruby example:

Code: Select all

class SomeKindaList(Enumerable):
   def each(self):
      # ...


Yet, I'm interested in what cases true multiple inheritance would be more desirable. It seems to be more dangerous, though.


Python multiple inheritance versus Ruby's mix-in mechanism are implemented
quite differently, but as far as an application programmer is concerned they
work and feel the same. As to which is more dangerous, the answer is "both".

They can both produces headaches in debugging and understanding code. The both
make it to easy to produce dependancies that can cascade through your code in
unexpected ways. Which is not to say that either technique is bad - they are
both very useful, but if they should not be relied upon to solve all problems,
especially in larger code bases.

Python allows for Object Composition with Interfaces and Adapters (aka Aspect Oriented Programming), as provided by the Zope Component Architecture. This is what Plone 3 uses, and it is a much cleaner, more explicit way than making heavy use of mix-ins. Having been involved with Plone since the early days, and worked with the code base when it was all done with multiple inheritance versus object composition, object composition is a much nicer way of constructing large applications.

WendelScardua
Posts: 31
Joined: Wed Dec 05, 2007 1:25 pm UTC

Re: "Python" discussion

Postby WendelScardua » Thu Dec 06, 2007 1:06 pm UTC

Someone mentioned Basic, and I remembered that I've spent 4 years programming QBasic at home ('97 ~ '01); i've recently "re-discovered" some of those programs and even put them online (I would link it here, if it wasn't forbidden).

Then came the Computer Science undergrad: C, C, C (hey, so those things i've done in qbasic had names !? "recursion", "stack", ... ), Java (ugh! why!?), Java (ugh!^2), Perl (nice!), Smalltalk (almost nice, but "do not want"), C again ....

Now I use Perl for work and for fun, and I like how it feels like a real language for me (like "english", or "japanese", not like "QBasic" or "C"). When I'm writing programs in Perl, i feel like i'm talking to the computer what I want him to do (the "Do What I Mean" principle).

One day I had to play with some python code (i was using pywikipedia to create a bot for some common tasks at desciclopédia, the pt_BR/pt_PT branch of uncyclopedia), and it really feels like a cool programming language.

I just don't have the same feeling towards it as I have towards Perl. When I'm (trying to) program in Python, it just looks like "real programming", not "talking to the computer". But, I think it's just my fault. Maybe if I tend to use more and more Python, I would be speaking Python fluently.

Also, Python looks like the best language to introduce someone to programming. It can be simple when needed - like QBasic - , powerful when needed - like C, Perl, etc.

The only thing I really missed in Python is a CPAN-like repository, with zillions of useful modules, and a related command-line tool. I guess I've already found it some months ago, but can't remember now ^^;;;

VirtualVoid
Posts: 40
Joined: Wed Aug 22, 2007 1:05 am UTC

Re: "Python" discussion

Postby VirtualVoid » Thu Dec 06, 2007 2:58 pm UTC

LDJosh wrote:Python & Perl have their different uses. It's comparing apples & oranges. They're both fruit, but you put apples in a pie, and you mix orange juice with vodka, ok? You could put oranges in a pie and put vodka in apple juice, but then you're just a damn idiot.

Thank you.

Getting into a religious debate about programming languages is like arguing that hammers are better than screwdrivers.

Languages excel at some things and suck at other things; the point is to choose the right tool for the task you're trying to accomplish. If I were working on some embedded system, I'd likely use C or some lower level language. If I were writing a large-scale server application where performance was necessary, I'd likely use C or C++. If I wanted to write a "program" to parse my log files and display some information about them, I'd use Perl, etc.

Look: if you know one, you can learn another just as easily. I don't like the current mentality of employers who are seeking "Full time <insert language here> programmers" (unless it's for a short-term project where time-to-market is critical). If you know C++ you can learn Java really easily. If you know Perl you can just as easily learn PHP, Python or Ruby. Sure, some paradigms may differ, but ultimately the higher level programming (and Computer Science) concepts are all the same. You may find difficulties in learning Prolog if you were brought up on C++ (as the concepts are very different), but the principles are the same.

Python, Ruby, PHP -- they all have very good uses. I've found Python to be a very elegant language, but I was ultimately turned off by the enforced tabbing and use of linebreaks to determine program flow. I'm a brace man, and find (for me) that it makes it easier to read code. I like a lot of the ideas behind Ruby although have only tinkered in it very briefly. I never really liked PHP but I know some die-hards that swear by it and would use nothing else. I love Perl, but I definitely hear the complaints about it.

Ultimately, however, it's all about choosing the right tools. Programming languages are just hammers and power-drills. Ultimately, your hands have to use those tools to build your house.

I know this won't end the argument over which is better, but I hope it sheds some light. If you try to accomplish a task in a programming language that's ill-suited to accomplish it, you're going to be unhappy.

Now, I'm going back to write some Brainfuck.
</post>

User avatar
LDJosh
Posts: 242
Joined: Fri Oct 26, 2007 6:07 pm UTC
Location: South Central, PA
Contact:

Re: "Python" discussion

Postby LDJosh » Thu Dec 06, 2007 3:26 pm UTC

Qbasic.

whitespace doesn't matter
no braces
easy to read
and makes bitchin' programs like this!
http://www.acidworks.com/

/sarcasm
//kinda...
--------
~Lameduck Josh
ninjajosh.com

dskippy
Posts: 30
Joined: Wed May 16, 2007 5:48 pm UTC
Location: Somerville, MA
Contact:

Re: "Python" discussion

Postby dskippy » Thu Dec 06, 2007 3:52 pm UTC

Guys, this is serious. I found this on Perl's dresser this morning:

#!/usr/bin/env perl
use warnings#igns
;die "Goodbye, World!\n";

While I completely support Randall's decision to move to Python (or Scheme) we need to be compassionate here.

-mike

p.s. Randall, you dog. Python is only 16 years old. At least Perl was legal.

User avatar
Otto
Posts: 22
Joined: Fri Oct 12, 2007 8:30 pm UTC

Re: "Python" discussion

Postby Otto » Thu Dec 06, 2007 4:32 pm UTC

This comic strip convinced me to look at Python.

Reading the fact that whitespace matters convinced me to stop looking.

Seriously, that's the dumbest thing in a language that I've ever seen. That alone makes Python fail my litmus test for languages I'll use. I'll stick to PHP, or Perl, or Java, or half a dozen other languages that are just as powerful and easy to use.

The thing language aficionados often seem to miss is that the language is just a matter of choice. It's the means by which you input your instructions to the machine itself, but the instructions are largely the same regardless of the language. There have been relatively few revolutionary ideas in languages in the past many years. Object Oriented Programming was one revolutionary idea, but it wasn't a matter of language, it was a different way to look at the concept of programming itself. See, a good programmer can use many languages to express their idea/program. But an excellent one sees through the language to the actual machine. The language itself ceases to matter, as it's just the interface, not the system actually being created underlying it.

Think of it like any other language. English is the means of communication only, not the communication itself. The language fundamentally doesn't matter, it's the communication itself that I'm trying to achieve.

So putting weird rules in your language, like saying that whitespace determines block structure, doesn't help. The argument that proper programs are indented anyway is irrelevant, the problems it introduces (having to use specific editors, shared notion of tabs = x spaces, etc) are greater than the problems it solves (not letting me explicitly specify block structure). Editors do auto-indentation now for other languages and have for years. When I type a { in C, I get automatically indented, until I type a }. This is a simple and easy way to determine blocks, I can specify them. Instead of hoping that editor A on machine A uses the same system of tabs=X spaces as editor B on machine B. Or even the same characters for tabs and spaces, those code page conversions aren't perfect you know, and I program regularly on no less than 6 completely different platforms.

So no, Python has failed me on the most fundamental level: Sanity. I almost said it failed on "ease of use", however I've not tried to use it, nor will I as long as it thinks that there's only one correct way to any given problem. A proper language makes it easy for me to express my idea using that language, it does not tell me that my idea can only be expressed one way, because that's provably false.


Return to “Individual XKCD Comic Threads”

Who is online

Users browsing this forum: No registered users and 81 guests