Amazingly Bad APIs
paulbuchheit.blogspot.com
paulbuchheit.blogspot.com
And it's not as if Java isn't giving you more flexibility. How do I tweak that Python code to make the image load faster? Can I get Bicubic interpolation on the resize? How well do those image objects integrate with other parts of python, i.e. are they basically just special objects for this library or could they be used in other ways later?
As a person who doesn't mind writing code and whose IDE autogenerates a lot of boilerplate anyway, I think I'll take the 100 line hit so I know what's going on.
Having everyone rewrite those 100 lines is really inexcusable. Throwing in a few convenience functions to make the common case simple would not detract from the "flexibility" one bit. It shows that they gave zero thought to what people will actually do with the library.
BTW, want to take a stab at writing the "save at different quality level" code? (since you don't mind writing lots of code) You can post your solution here.
By the way, I think it's kind of unfair for you to link to the interface definitions rather than some implementation for Java. java.awt.Image is probably just as inscrutable, but at least it does something.
edit: While I'm at it, one point that I didn't quite make clear, but should be noted is that Image in Java is used all over the place, so its interface is going to be pretty much targeted at not missing any possible use case. If you're interested in a narrow-scoped pixel image application, why not use some Java image processing library? Sun's got one: http://java.sun.com/javase/technologies/desktop/media/jai/
Owch! that will come back to bite you. Wouldn't it be better to re-write, re-factor to reduce complexity and get cleaner code?
'... think it's kind of unfair for you to link to the interface definitions rather than some implementation ...'
because it's the interface that we are stuck with & have to work with
'... If you're interested in a narrow-scoped pixel image application, why not use some Java image processing library? ...'
because it's not COSHER & I do not want to be locked into using non-free software ~ http://wearcam.org/cosher.htm
As to your other points, I'm not sure why you assume copying code leads to that code being bloated or unclean. Bad assumption. Personal preference on the latter point, though it's pretty easy to find open sourced libraries.
DEFECTS if you cut+paste code from place to place and find a single defect in the block you have to go and find all the other instances you have pasted the code.
BLOAT If you cut+paste code it increases the number of lines of code within the codebase so the LOC increases.
Software development within a startup context is about creating code that is "reliable, smaller, cleaner & faster". Reusing code is good but not at the expense of modularity, bloat and defects. Not using cut & paste as a development practice isn't personal preference, its DEV 101 ~ http://en.wikipedia.org/wiki/Copy_and_paste_programming
You'd be copying its bugs too. And you wouldn't pick up any future bug fixes automatically. Copying lines of source like this is cut-and-paste programming, rife in MS-shops everywhere.
Code copying is pretty much a standard thing. I don't know why everyone's hating on it so much. The Ruby on Rails community has pretty much built itself on code copying...
I don't know why there'd inherently be bugs in a decently simple chunk of code. There's often bugs, especially if the language or API is unwieldy and getting in the way of expressing the aim. Look at how easy it is to write an incorrect binary search of an array. Then there's common "off by one" or "fence post" errors. And people copy one line to a line below but only change one of the two things that need changing.
And we're not talking about a huge system, so whether you catch bug fixes is irrelevant. Paul's estimating 100 lines. You don't want to have to be detecting bugs, let alone fixing them, in someone elses code of that size if the well-tested, not grabbed off the Internet, library provides a routine to do it for you. If there's a bug in PIL then everyone will get the fix on the next release, not so for a copy-and-paste code.
Code copying is pretty much a standard thing. Yes, there's much wrong with coding practices today.
I don't know why everyone's hating on it so much. We've seen the outcome. We've maintained systems where people were doing this twenty years ago and the problems it caused then are still being created today.
The Ruby on Rails community has pretty much built itself on code copying... Yes. 8-D
If whatever operation you need is not already implemented by a Python module you can just write those 100 lines of fast C++ code and then call it from Python.
As far as knowing what's going on in general you can always look at the Python source code.
set sk [open news.ycombinator.com 80]
And you're in business. If you want to do more complex things, you can then operate on that socket, fiddling with all the options (blocking/non blocking, buffering, etc...).
The lesson is: make the obvious thing really easy, and give the user a means to access advanced functionality without requiring it.
Matt don't let the Architect Astronauts scare you ~ http://www.joelonsoftware.com/articles/fog0000000018.html
Usually, the first thing you think of (in this case, the way the python is implemented) is usually best. If you need something more specific, a specific, instead of abstract, solution is probably better.
http://www.joelonsoftware.com/articles/LeakyAbstractions.html
The problem with 'over-abstraction' is not too much abstraction per se, any more than the problem with 'oversimplification' is excess of simplicity, or the problem with 'overgeneralization' is too much generality.
Abstraction, simplicity and generality are, in themselves, desirable properties in a design, since they reduce the bulk of design concepts we have to fit in our heads. You can't have too much of these.
You can, of course, make things worse for yourself by neglecting other design goals while striving for a particular one, or by stalling progress in your project by spending too much time in analysis paralysis.
The decision is not only between less or more abstraction, though. There are 'better' and 'worse' abstractions, as measured by their ability to show what is important for the client and hide the irrelevant. In Joel's examples of leaky abstractions, you can say 'too much' is being hidden. I'd rather say the wrong things are being hidden, or that it's done in the wrong place. You could conceivably hide 'more' irrelevant details while still letting every part of your program see what it needs.
To further complicate matters, the fitness of an abstraction for practical purposes depends on cultural factors. Some powerful abstractions only help if you've made the investment to learn and internalize a certain way of thinking about programming. On top of that, you may need to consider the skills and preferences of your audience.
In the example at hand, if Java needs 100 lines to perform an operation, while Python does away with 3, it's hard to argue that Java is being too abstract, or, indeed, more abstract at all. You can say it overindulges in 'abstractions'. But note that the end result burdens the user with lots of details that are irrelevant to them. That is exactly opposite to what abstraction is all about.
That said I am not sure the imaging API is as bad as Paul makes it. My guess is that the jpg-api of Python is more like the "escapeMYSQL"-method in PHP. The Java API is very general, so that you can plug in different codecs and encode the image in whatever way you want (JPG, TIFF, GIF, whatever). Can Python do the same?
On the other hand, only JPG matters for Web development, so the generalised API might not be much of an advantage.
Anyway, I wasn't arguing; just pointing out the fact in case you were interested. I wasn't even aware that there was any type of jpg support in the standard Python library.
hmm I thought that would have been a positive attribute to look for
Java, unfortunately, is full of these crappy APIs because it went through multiple committees.
http://schmidt.devlib.org/jiu/introduction.html
Don't know about the quality, I just yahoogled it.
:)
I've actually considered writing a photo sharing web site (since there aren't any good ones), but that's not what I'm doing right now.
Yes, the Java imageio API is painful. I used it to create a function to get image dimensions, but having experienced the pain once I just used a shell script for resizing.
If you're still struggling with multiple-image uploads, one approach is to have the user make a zip file; not so hard today, as you can right-click a set of files in your file browser. Also see
http://img.ourdoings.com/windows.html
Windows XP also has a web publishing wizard that actually works well once you figure out how to use it. Feel free to reverse-engineer the ourdoings.com implementation of it.
You probably aren't going to write a photo sharing web site if you considered it and haven't started yet. You kind of have to be obsessed with it to work through all the details. Since you haven't started you aren't obsessed, and probably wouldn't enjoy it.