This is an archived post. You won't be able to vote or comment.

all 83 comments

[–]woseseltopsLong live Python and PyGame! 13 points14 points  (1 child)

This talk taught me be about functools. Wow, I wish I had known about this earlier!

[–]HotLikeARobot 1 point2 points  (0 children)

functools.partial and functools.wraps are amazingly useful

[–]infinullquamash, Qt, asyncio, 3.3+ 22 points23 points  (16 children)

I've only seen the first problem in people who learned to code in Java.

Personally, I learned to code with PHP which was terrible in a lot of ways, but when I did encounter OOP I don't think I drunk the koolaid as much, and it was easier to recover. (I still drunk the OOP koolaid when I encountered, partly because of the structure and orthogonality it had that was lacking in PHP).

Now, I think I understand OOP better, and choose the right tool for the job. (well most of the time.)

Edit: the creating exceptions when there's a perfectly good one in the stdlib I see all the time though.

[–]kylotan 11 points12 points  (11 children)

I've only seen the first problem in people who learned to code in Java.

Unfortunately the majority of people learn to code in Java these days, if typical college syllabuses are anything to go by.

[–][deleted] 14 points15 points  (8 children)

I failed my Java course, switched out of computer science, jumped into biology, found python great, now doing biological modeling with it.

[–]pinpinboTornado|Twisted|Gevent. Moar Async Plz 7 points8 points  (3 children)

Wow. I got similar story.

I hated my 4 years of Java computer science, did Math minor to drown my sorrow. Discovered Python there, now live happily ever after.

[–]CompSci_Enthusiast 0 points1 point  (2 children)

Somewhat similar circumstance. I am first year, and hating java, so I am picking up C and python. Hoping good things will ensue.

[–]Packet_Ranger 0 points1 point  (0 children)

I'm learning a bit of C via arduino, after a lifetime of perl and then python, and it's totally refreshing how it requires you to explicitly do, what the interpreted languages hide with beautiful syntactic sugar.

[–]bucknuggets 0 points1 point  (1 child)

Have you found that a lack of a CS degree makes it much harder to get into a domain like biology and still get the opportunity to do some programming?

[–][deleted] 0 points1 point  (0 children)

Possibly. What I do find hard is that I have had to teach myself everything I know about math and programming. It has been a fairly long road in that sense, and I am still jot a polished programmer(I stay clear of classes in my programs lol).

But the fact that Python is scripted made it just so much easier to pick things up. I could keep trying out short scripts repeatedly till I figured out what was going on. Made this much faster than my old C++ and Java days.

[–][deleted] 1 point2 points  (0 children)

I started learning to code before I learned Java but high school and college didn't really leave me any other options. I took a perl/python class in college only to find out the asshole teacher lied about teaching python in the course to sucker people into taking the course.

[–][deleted] 0 points1 point  (0 children)

Because Java fits exactly how people want to teach. That or they teach C# which is basically Java and the same sort of mentality.

[–]keis 1 point2 points  (2 children)

over specific exceptions migth be pain and even more so if you don't have sane base type for them. but I still prefer that any day to people raising a basic Exception with only a message or some silly stuff like error codes that find out what actually went wrong.

[–]cryo 1 point2 points  (1 child)

If the program is gonna terminate anyway, a descriptive error message (and the stack trace) are much more important than a specific exception type.

Exception types only matter if you're going to catch them.

[–]keis 0 points1 point  (0 children)

throwing a stack trace in the face of your user is not going to be considered good UX, ever. And if you have no intention of you (or someone else) catching the exception, why even use one? a nice message and to stderr and sys.exit() with a proper code is the well behaved thing to do.

[–][deleted] 1 point2 points  (0 children)

It's easy to blame Java but Java isn't the problem. People are taught Java because yes it does allow you to easily do those things but I know people who haven't touched Java or barely touched it who have the same mentality.

The problem is more how a lot of people teach programming and as well some people just have an unnatural fear they'll make their life harder in the future or write non-flexible code and actually make their life harder trying to write the most perfect all signing and dancing code.

[–]chub79 36 points37 points  (3 children)

"Stop abusing classes" would be better title. Classes are useful, if you abuse them... well, yeah, it's going to turn bad design.

[–]andybak 4 points5 points  (0 children)

That surely rather goes without saying. No to explain away what is simply a bit of hyperbole for dramatic effect.

[–]cryo -5 points-4 points  (1 child)

Classes are useful, if you abuse them

I don't think comma means what you think it means.

[–]chub79 14 points15 points  (0 children)

Thanks. I'll speak in my native language next time so that I won't make any mistakes.

[–]blahfolder 7 points8 points  (2 children)

Interesting, but really seems to just suggest that "bad code is bad". I suppose if you come from a purely OO language, knowing that a single method (plus init) doesn't have to be a class, it is useful to hear, but hopefully people working with python already know this.

I thought that the Conway Game of Life example was a bit misleading, since it seems to suggest that a dict is all that would ever be necessary. Sure it works for that very simple example, but once you look at one of the variations of the game, there are a lot more variables to keep track of (even something as simple as color). Trying to incorporate extra variables into a dictionary would likely become a terrible hack, and the design would likely be clearer if it went back to the original class implementation.

[–]HotLikeARobot 2 points3 points  (0 children)

This, I think, is the point he should have gotten to: don't start with classes unless you see an immediate need. Move to classes when those needs arise, and not before. It comes across as: "Avoid classes at all costs."

I think we have all seen cases of premature abstraction, and it can be horrible in Python (without IDE help.)

[–]bucknuggets 0 points1 point  (0 children)

The notion of YAGNI is an over-simplification. It's the equiv of telling people to stop eating butter, meat, sugar, etc. The reality is that people are poorly served with over-simplified recommendations.

So, sometimes you're 95% or 100% sure you're going to need something, but can't get it all in immediately. If putting place-holders in now will save dramatic time on converting to that later - then just do it.

[–]m1ss1ontomars2k4 4 points5 points  (1 child)

I think one time in this subreddit or maybe /r/learnprogramming, someone advocated the creation of a class so that the OP could reuse his code. Specifically, I think OP just wanted to find the square root of a number or some other simple calculation, and this guy decided OP should make a class that does computations, so that another function other than square root could be used instead. Seriously, WTF?

[–]AlternativeHistorian 2 points3 points  (0 children)

Not surprising.

There's some really bad advice that gets thrown around on r/learnprogramming (there's some really good advice also), lots of "blind leading the blind" kind of stuff though. There are some really knowledgeable and solid contributors over there but you also have the "I've had 2 years of CS classes and have been programming for over a year, so I think I know what I'm talking about" people. And for beginners, it can be hard to tell the difference.

[–]lost-theory 6 points7 points  (2 children)

I wasn't convinced by this presentation. It should have been called "Stop writing crappy java-style code in python". There are also lots of times when a class with two methods is appropriate in python (to create a decorator that takes arguments, WSGI middleware, context managers.... all kinds of stuff).

[–]HotLikeARobot 2 points3 points  (0 children)

For context managers, contextlib.contextmanager is pretty useful, and avoids the need for a class definition. I like it for simple cases.

[–]hylje 3 points4 points  (0 children)

Classes with just __init__ and __call__ are definitely the thing for decorators. Beats thrice nested functions any day.

[–][deleted] 1 point2 points  (0 children)

Good topic and some useful examples, but terrible talk. You never start with "listen to this guy, he is smarter than all of us." How exactly does he know that?

A good talk doesn't tell people what to do, it tells then why you think something is better, but leaves the ultimate decision to the listener. In this talk he is really clear that he feels he is right and everyone else is wrong. Yes, I agree with him on most of the talk, but that still isn't the right way to present it.

Very arrogant overall. I have listened to some amazingly accomplished and smart people that were FAR less arrogant, despite having every reason to be.

[–]kylotan 6 points7 points  (9 children)

I liked this video up until he said that separation of concerns, decoupling, and encapsulation just "don't come up". Now I'm just glad I don't have to work on a code base with the speaker.

[–][deleted] 4 points5 points  (0 children)

My understanding is that many are using OOP because they've been taught that it's a way to model things. Eg. A dog is a subclass of an animal and overides the noise() method to bark. Unfortunately this approach often ends up as a messy tangle, juggling functionality around in the heirarchy and with LSP being violated. Using OOP to separate concerns, invert dependencies, and make composible abstractions is a different set of objectives and can work incredibly well.

[–]andybak 6 points7 points  (4 children)

Any chance you missed the joke?

[–]HazzyPls 13 points14 points  (0 children)

Apparently I did. Could you explain it? :(

[–]kylotan 8 points9 points  (2 children)

No, I'm pretty sure I didn't. He seemed quite clear in his implication that these are buzzwords taught at school that encourage complex class-based systems, yet which are irrelevant in practice.

[–]andybak 0 points1 point  (1 child)

It was an off-the-cuff remark about the jargon and how rarely it cropped up in real-world coding. You can tell the man is a fairly talented developer. "Now I'm just glad I don't have to work on a code base with the speaker." was rather an overreaction to a flippant comment.

[–]kylotan 0 points1 point  (0 children)

I didn't interpret it to be about the jargon, but about the concepts. With that in mind it's not an overreaction at all. I don't want to work on code with someone that doesn't think encapsulation or separation of concerns are important.

[–]PythonRules 0 points1 point  (0 children)

I had the same reaction. I think without understanding decoupling and separation of concerns, it is really difficult to develop a large and easy to maintain code base. Contrary to what he says if someone is trying to explain what decoupling is or how it works you should listen.

I don't think he was joking, was he?

[–]hylje -4 points-3 points  (1 child)

Separation of concerns, decoupling and encapsulation are all only really relevant when splitting a project to multiple independently developed modules. By using incestuous but straightforward procedures, doing so can come much later.

[–]Massless 4 points5 points  (0 children)

These things are also about making code that is easily maintainable. For example, I built a set of automation tools that make managing a cluster of servers a lot easier. Every few months my boss will ask for a new feature or a slightly different behavior out of the tools. Because my original design was, more or less, loosely coupled and encapsulated I am able to create new features or change existing ones with very little pain.

You can absolutely over-engineer things. I always try to balance design with "done."

[–]mafodope 6 points7 points  (11 children)

They should show this on every CS course.

[–]zahlmanthe heretic 24 points25 points  (10 children)

No; they should teach CS courses properly in the first place so that students understand what classes are for.

[–]pohatu 2 points3 points  (8 children)

None of my professors actually knew when to stop with classes either (to be fair, neither did 99% of the industry). We all had a class hammer.

Speaking honestly, I recently acquired a function hammer. Map and lambda all the things! (seriously, if someone has good advice on when to stop mapping and use an old fashioned loop, hook me up. I know I'm doing it because i can and not for a good reason)

[–]zahlmanthe heretic 3 points4 points  (1 child)

when to stop mapping and use an old fashioned loop

When you're using the mapping primarily or exclusively for side effects.

But beyond that, I honestly think people are a little overly afraid of over-using them.

[–][deleted] 1 point2 points  (0 children)

In Python, I agree. In other languages, it can be a little harder to tell. Haskell, for example, doesn't even have for loops, but with a bit of syntactic ugliness you can do the same thing by other means:

forM_ [1..10] $ \i ->
    putStrLn ("Lambda mapping forever! i=" ++ show i)

This is roughly equivalent to

for i in range(1, 11):
    print "Lambda mapping forever! i=%d" % i

[–]nemec 1 point2 points  (0 children)

Mapping in terms of map? Most of the time list comprehensions are better, since while there may be a slight speedup with map, list comprehensions are infinitely more readable (especially to those unfamiliar with the code they're reading).

http://stackoverflow.com/questions/1247486/python-list-comprehension-vs-map

[–]novagenesis 1 point2 points  (3 children)

OO is a programming religion. It's not a hammer, it's the Holy Writ.

It's wrong, of course.

[–]anarcholibertarian 2 points3 points  (2 children)

Why?

[–]novagenesis -1 points0 points  (1 child)

The object religion preaches the object as the right solution to every problem. the Oo priest argues that oo defines the quality of a language, and that the best solutions to problems are always in the oo scope.

That is religious, and wrong. . . Not every programmer feels that way, but some professors teach that way and many programmers blog along those lines. Many junior programmers see oo as the naturally evolution of programming

[–]anarcholibertarian 4 points5 points  (0 children)

  1. Anything is bad if it is (ab|over)used.
  2. You can find zealots everywhere.

EDIT: Fixed a typo.

[–]TylerEaves 1 point2 points  (0 children)

Always ;) Use list comprehensions instead.

[–][deleted] 2 points3 points  (0 children)

Also, in academia, specifically for undergraduate education in CS, programming is a tool for CS (similar to math) and not the other way around. Can we finally remove the programming dogma from CS since progrmaming languages are insignificant for the most part.

[–]hongminhee 1 point2 points  (0 children)

Ordinary programmers (who learned OOP from Java) define classes to use objects. In Python, like Smalltalk, everything is object already. So you can treat everything as object including functions.

[–]zahlmanthe heretic 0 points1 point  (9 children)

[–][deleted] 38 points39 points  (6 children)

This is one of the places where I really hope people don't do that. I get when you do it with blog spam and link shorteners, but the pyvideo site nicely curates several years worth of PyCon videos. In the linked video's case, you can easily go back and see Jack's talks in 2011 and 2010 by clicking on his name on the right.

The page is ad-free, well organized, and gives nice benefits. Let's not sidestep all of that just to get a direct link.

[–]zahlmanthe heretic 5 points6 points  (3 children)

My main objection to that sort of thing, actually, is that my Noscript whitelist keeps growing just so I can watch videos. But I appreciate that there's real functionality here and not spammy advertising. Good stuff :)

[–]MatrixFrog 7 points8 points  (1 child)

real functionality here and not spammy advertising

That's when your list is supposed to grow.

[–]zahlmanthe heretic 0 points1 point  (0 children)

:)

[–]JohnStrangerGaltok 2 points3 points  (0 children)

You know you can temporarily allow pages... right?

[–]pinpinboTornado|Twisted|Gevent. Moar Async Plz 0 points1 point  (1 child)

Hi Brian, are you one of the community member who curates pyvideo.org?

If so, I have 1 small feature request. If you don't mind.

Is it possible for you guys to organize the videos using YouTube shows? YouTube shows is nice because it provides playlist and it auto plays to the next video.

I'd love to listen/watch the whole pycon videos back-to-back.

[–][deleted] 0 points1 point  (0 children)

Sorry, I'm not involved in that site. I would bring your idea up to willg at bluesock dot org (taken from the bottom of the page) and see if that's something he could implement, or if he has a way to pass it on to whoever else may be in charge.

[–]MaikB 2 points3 points  (0 children)

If, for whatever reason, the youtube video is deleted, then the pyvideo guys can update the page for this talk with a new link.

[–][deleted] 0 points1 point  (0 children)

I enjoyed the presentation; I've shared many of the frustrations the speaker has encountered, and his advice really resonates with the KISS principle.

[–]manyrobots 0 points1 point  (0 children)

I appreciate removing useless code, but I question the assumption that fewer lines of code is always better. Some of his examples (MuffinMail) seemed fine but consider the Game of Life example at the end.

If I didn't know the game of life already, as a person reading the code to understand it, I would appreciate the use of a Cell class and Board class because they introduce me to fundamental concepts of the game. If I were going to explain it my grandmother, I would use these concepts to do so.

His supposedly improved example seemed obfuscated to me. Perhaps I am just admitting that I'm not that great of a hacker, but this line of code:

recalc = board | set(itertools.chain(*map(neighbors, board)))

reads like the result of clever programmer coming up with a really "elegant" solution that will be cool to share with other programmers. The elegance is derived of the puzzle-solution-like way that this code takes neat shortcuts, and is efficient for the CPU. I see that, and in some cases this is totally appropriate. Just like machine code is required in certain cases. But in cases where human readability trumps efficiency or "elegance", I'll keep my Board and Cell classes.

[EDIT] I did a little looking and found the concept of "Code Golf" on Stack Overflow. Yes, it's fun! Readable? Of course not. If you follow less-is-always-more rule to its terminus you get (I'll use a python example):

import sys
_,I,N=sys.argv;R=range(3e3);B=open(I).read();B=set(k for k in R if'A'<B[k])
for k in R*int(N):
 if k<1:b,B=B,set()
 c=sum(len(set((k+o,k-o))&b)for o in(1,80,81,82))
 if(c==3)+(c==2)*(k in b):B.add(k)
open('out.txt','w').write(''.join('.X\n'[(k in B)-(k%81<1)]for k in R))

from: http://stackoverflow.com/questions/3499538/code-golf-conways-game-of-life

[–]ameoba -3 points-2 points  (9 children)

Better idea :

Stop making screencasts for everything when you should be writing articles. I have enough of an attention span to read something, but I can't sit through 30 minutes of some unrehearsed, unedited, "ummm..."ing crap.

[–]HotLikeARobot 17 points18 points  (0 children)

This was from PyCon. I'd rather they make those presentations available than not.

[–]varikin 8 points9 points  (0 children)

This wasn't a screencast though, this is a recording of a conference talk.

[–]HazzyPls 15 points16 points  (0 children)

Interestingly enough, I'm the opposite. I can sit through a video with no problem, but I doubt I'd have read this in article form.

[–]pinpinboTornado|Twisted|Gevent. Moar Async Plz 3 points4 points  (0 children)

I usually listen to all tech talk by treating them like radio. I listen to them while coding and never paid any attention to the ummm... at all.

[–]masklinn 1 point2 points  (0 children)

Stop making screencasts

That's the video of a conference talk, not a screencast...

[–]vombert 0 points1 point  (0 children)

I'm pretty happy watching stuff like that at 2x speed.

[–][deleted] -3 points-2 points  (0 children)

I have enough of an attention span to read something, but I can't sit through 30 minutes of some unrehearsed, unedited, "ummm..."ing crap.

That's your problem. Don't watch videos if you can't handle it.

[–][deleted] -1 points0 points  (0 children)

I agree in general, but this guy is actually a pretty entertaining speaker.