Live data from Hacker News

Python for Humans

python-for-humans.heroku.com

101–108 of 108 posts

Re: Python for Humans

#101
post #76

I guess I agree things could be simpler, although the cries of "garbage!" were a bit much. I wrote a wrapper function around urllib2 about 5 years ago and haven't looked back.

That's precisely the problem: your wrapper helps you...and only you (ie, it's worthless).

It wasn't that hard... didn't mean to imply it took five years.

Re: Python for Humans

#102
post #70

Earlier quoted context omitted.

I didn't find making moderately complex HTTP requests in Ruby to be much more fun than urllib2 in Python. Do you have a library you recommend?

I like httparty or mechanize, but feel free make your own choice over here https://www.ruby-toolbox.com/categories/http_clients

I've tried rest-client, em-http-request, and mechanize. I don't recall their specific failings except for mechanize, which seemed to work awesome in 95% of cases and produce cryptic errors with the latter 5%. I will take a look at httparty, though, thanks.

Re: Python for Humans

#103
post #64

Earlier quoted context omitted.

The acid test is to see if you can avoid terms like "Writer", "Printer", and whether someone is able to explore your API using the REPL. >>> import log >>> log.log(log.CRITICAL, 'PrintModule', 'Printer failure', sys.exc_info()) PrintModule: Printer failure >>> print log.configuration [ ] >>> log.configuration.clear() >>> print log.configuration [] >>> def send_mail(level, module, message, exception): ... import smtpl…

Thanks. I like the idea of classes masquerading as functions. And easier configuration. I had actually started writing this 2 days ago as something just for me, but after reading this decided to try something new.

Also keep the following in mind. You don't need to use Singletons in Python. The following code smells in Python.

     log.getLogger()
use a module instead.

Re: Python for Humans

#104
post #84
post #57

I blame GOF for making Python Standard Libs hard. The patterns described were for an OO system where functions were not first class. Python didn't need to be complicated. If you have a look at the older libraries, most of them were written in a procedural style. Not only that, it is very amenable to testing in the REPL. import smtplib s=smtplib.SMTP("localhost") s.sendmail("me@my.org",tolist,msg) note the absence of…

I've been programming python for nearly 10 years, but your comment just helped me clarify a thought that I've had for ages but have never been able to put in to words before: a well designed Python API is one that can be effortless used within the REPL. And that's why urllb2 sucks.

Writing good python has been more of a challenge for me lately. The more C#/Java I write, the harder it is for me forget dependency injection, factories, etc and just feel the freedom Python provides.

Re: Python for Humans

#105
post #84
post #57

I blame GOF for making Python Standard Libs hard. The patterns described were for an OO system where functions were not first class. Python didn't need to be complicated. If you have a look at the older libraries, most of them were written in a procedural style. Not only that, it is very amenable to testing in the REPL. import smtplib s=smtplib.SMTP("localhost") s.sendmail("me@my.org",tolist,msg) note the absence of…

I've been programming python for nearly 10 years, but your comment just helped me clarify a thought that I've had for ages but have never been able to put in to words before: a well designed Python API is one that can be effortless used within the REPL. And that's why urllb2 sucks.

This is the thing that got me off OO altogether. Typical OO code is hard to call from the REPL. You have to know what objects to construct before constructing an object that has the method you want to call, which probably requires more objects to be constructed and passed as args, etc. Yet more often than not the function in question is simple enough that it ought to be easy to call without all that baggage. That got me so annoyed that I finally just started making all my functions easy to call from the top level and never looked back. You're right that this leads to better designs.

Re: Python for Humans

#106
post #60

Earlier quoted context omitted.

Well, Perl's CPAN has an uninstall feature. That's kind of nice.

cpan is very much not a std lib. PyPi is equiv.

Depends on what your definition of "std lib" is.

If you say a "std lib" is something that is installed along with the language, then CPAN fits the bill.

    $ corelist CPAN

    CPAN was first released with perl 5.004

Re: Python for Humans

#107

Earlier quoted context omitted.

cpan is very much not a std lib. PyPi is equiv.

Depends on what your definition of "std lib" is. If you say a "std lib" is something that is installed along with the language, then CPAN fits the bill. $ corelist CPAN CPAN was first released with perl 5.004

That's more of a standard tool, not a standard library. Rather, a library is a collection of reusable components. A Standard Library, then, are pre-equipped collections of reusable components. Here, we define "reusable" as invokable from within the language, as first-class constructs.

Even if CPAN was a standard library, that which you install from it is clearly not, which is what the argument to date has centered around.

Re: Python for Humans

#108
post #95
post #92

Earlier quoted context omitted.

> If anyone remembers, Java had to do OO in a > big-style with OO everywhere -- there were no > alternatives. You can write Java that isn't heavily OO, but you have to implement alternatives to sections of the stdlib that most people assume or take for granted. Related to what you're saying about the GUI, I'd be interested to see a detailed summary of what the Lighthouse people did, and how it was different to Java.…

I've struggled through a few Cocoa tutorials. I think the programmer creates a delegate object which handles events. These delegates are assigned to UI elements, similar to how one would addMouseListener to a Java UI element. I may be entirely wrong here. Perhaps someone who knows can put the facts straight.

UI elements typically gets assigned an instance of an object (target) and a symbol representing the object's method (selector).

In Cocoa touch, it's:

    [mybutton addTarget:someObjectMaybeSelf action:@selector(onClick) forControlEvents:UIControlEventTouchupInside];
It's broken into separate methods in Cocoa but it's similar. You don't need to and usually don't create separate classes for targets.

The framework usually use delegates when a data source is needed. (for example to build up a table, you need to specify how many rows, what goes into each row etc).

Cocoa touch is really clean. Cocoa is still nice but a little messy.

Post reply on HN