Are dynamic languages just a temporary workaround?

This can unleash so much hate mail, but here it goes, my inbox is ready!

Are dynamic languages just a temporary workaround? I’m not sure! I’m switching between the two types of languages all the time: Java, Python, C#, JavaScript. I’ll try to make the long story short.

Statically typed languages, like Java and C#, are nice because when you do

blah.bleh()

you know that blah’s class has a bleh method, at compile time. But better than that, when you typed “blah.” you get a list of methods, and you already know whether there’s a bleh method or not, and if you typed bleh and it doesn’t exist, the IDE lets you know, no need to wait for the compiler. Also you can do very deterministic refactoring, renaming all “bleh” for “bluh” for example.

Statically typed languages are not nice because they are very verbose and require a lot of boilerplate (if you’ve used Haskell, just bear with me for now please), so you end up with things like:

List[Car] cars = new List[Cars]();
foreach (Car car in cars) {
    car.Crash();
}

How many “cars” do you read there? And that’s a nice example. There are worse. So come dynamically typed languages and you can write:

cars = []
for car in cars:
    car.crash()

You have less cars, and less (no) lists. That means you are more productive. You start chunking out code faster without having to stop and think “What type of object will this or that method return?”. But crash() can crash your application instead of just the car because you can’t know if it exists until run-time. That might be OK or not, testing and whatnot.

Then comes C# 3.0 where you can do:

var cars = new List[Car]();
foreach (var car in cars) {
    car.crash();
}

And you can see that syntactically it got closer to Python, which is what gives you the productivity. Don’t know the type? type “var”. But semantically, it’s still statically typed, like the previous statically typed example. You know that car is going to be of some class that has a crash method. You can actually know car’s class at compile time, no need to run it.

That’s called type inference. You don’t have to specify the type where the compiler is capable of inferring it for you. C# type inference system is still very limited (but better than Java’s). Let’s see an example in another language

cars = []
map crash cars

That means, create a list called cars, call the function crash on each car. Would you say that that is a statically typed language? or a dynamic one? I’d say it is dynamic, but it is static. Very static. It’s Haskell. Haskell’s compiler will infer all the types for you. It’s amazing, you’ll write code as robust as with C#, but as terse as Python’s (Monads will then kill your productivity, but that’s another story).

In Python 3 you can define types for arguments. They are mostly useless, but it’s an interesting direction. I think the best it can do is that when a program crashes it’ll tell you: “function blah expected an int, but got a float, not sure if that was the problem, but you might want to look into that”.

Now, my question is, are dynamically typed languages just a temporary workaround? As our compilers get better, our computers faster, will statically typed languages keep giving us as many or more reassurances about our code and utilities while at the same time they become as simple and terse as dynamically typed languages? Or will dynamically typed languages start to gain types and over time be more static without the programmers that use them ever noticing?

My question is, will we in the future, 50 or 100 years, look back and said “Dynamically typed languages where a temporary workaround to statically languages being painful to use when human beings and their toy computers were so primitive?” in the same way we can say today that “non-lexical scope was a limitation we had and have due to the limitations of computer hardware 30 years ago”.

Reviewed by Daniel Magliola. Thank you!

Advertisements

Almost losing faith in a product

cakeSeth Godin wrote an interesting blog post titled “Two ways to build trust” in which he says that, to gain someone’s trust, you have to either be very professional, or very human. You are either like Apple: everything just works because they are super professional, or you are Joe the Baker who would make a custom cake for you.

The problem is when you try to be like Apple and stuff doesn’t work or you try to be like Joe and your cake says “Made in China”. I’ve never thought about it consciously, but I’ve felt it, and it makes perfect sense.

I was using an application in my Android phone called BeyondPod. It’s basically a podcast grabber. I liked the application and I wanted to buy it. I was using a limited version. They offer you two ways to buy: through the Android Market, the usual way; or if you live in a country where the paid applications are not available, like me, you could buy a license on the web site. That’s very professional.

Also the application is quite good. So that was another hint that the maker was a very professional team.

When I was ready to buy I went to the web site and it looked so 1998ish. Oh-oh. Not good. I’ve looked for a way to buy outside the Market and I’ve found two. Buying it on-line and paying with Paypal or using an alternate Market. The Paypal link didn’t work. Double oh-oh. That alternate market was hard to use, so I’m not totally sure if this is correct, but it seemed the application was not there. Strike three?

By this point, I’ve already tried to buy the app through several days, failing each time and just going back to whatever I was doing before. The only thing that kept me coming back was that I was using the app, liking it and wanting the unlimited version.

There was no contact address for support. One day, fed up, I signed up in their forum and said “I want to pay! How?” I wasn’t expecting any answer really, but about 42 seconds latter came a reply “Oh, the link was broken, try again.” That looked like the developer of the app, although he never mentioned that. That’s good. It may not be an Apple, but a Joe the Developer.

I went to the site, clicked on the Paypal link and was redirected to another web site, a Paypal-clone. That’s it, too much. I’ve dropped a bomb on the forum: “I’ve clicked the paypal link and it sent me to another web site, looks very scammy, I’m not putting my credit card number there”. And I proceeded to search for another podcast reader.

4.2 seconds latter came “My apologies, that’s my fallback merchant account, the Paypal one is working again”. Having a fallback account? That’s very professional. I know many companies working with Paypal, moving thousands of dollars, and not having a fallback transaction system. In a sense, this guy showed a lot of professionalism in some respect, and being a human being willing to solve the problems for the parts not very well done. I paid right away.

I almost lost my faith in the product and company, but the owner wasn’t afraid of acting like a little company and that bought me over. I don’t expect a podcatcher for a niche platform to be developed by a corporation full of things with “Enterprise” in their names. I expect it to be developed by a guy on a basement and that doesn’t mean I won’t pay for it.

Reviewed by Daniel Magliola. Thank you!

If I were in charge of Audible

audibleI have one little idea to implement for Audible: make it free for blind people.

I’m sure there are channels to verify whether someone is (legally) blind: government certificates, associations, or something like that. On third world countries, audio books for blind people are a rare and expensive luxury. Building a public library of them that can be accessed for free is a painstaking process that some volunteers do. And here I am talking about collecting cassettes.

I don’t think this market would represent huge numbers in Audible revenues (although it’s a big market, as show by screen readers which are only useful for visually impaired people). And before you say “but an mp3 is of no use to someone with a cassette player”, I’m sure it is much less effort to download an mp3 and record it in a cassette than finding the cassette with the book in the first place. Some volunteers would do it for people with sight problems that want to access books and have no means.

Unlike screen readers, Audible is useful for everybody and providing a free service to handicapped people is an amazing thing to do, and if played correctly, also a very good PR campaign. If not free, it should at least be very cheap.

Reviewed by Daniel Magliola. Thank you!

Redirecting on load

other-doorOf all the bad practices I see on the web this ranks as very bad and I believe it’s not mentioned enough. It’ll easily make it to my personal top 5.

I go to a web site, like example.com, and I immediately get redirected to an ugly URL beast, like example.com/news/today?date=2009-06-30&GUID=5584839592719193765662.Wha? Why? First, the site broke any chance I had of making a bookmark of it with just one click. I don’t want to bookmark yesterday’s news (look at the URL, it has a date), and what’s that GUID? Oh well, I go and make the bookmark, pointing to example.com, by hand, because I have no other way.

Even if it only redirected me to example.com/news/today it’d be pretty bad. That URL may not work tomorrow due to changing software. Or what can be even worse: the software and the content get revamped, the URLs changed and everything is cool again, and since the developers are smart people they leave old URLs working. So my bookmark works, but shows obsolete information.

With my crazy browsing habits (open a trillion tabs, fast, fast, faster) I go to a page, leave it loading, and when I go back and see a weird URL I end up wondering whether I accidentally clicked on something or something weird happened. I have to go back and check.

It gets even worse when the URL is rather obscure. My e-banking site has this issue. I go to the bank home page where I can find the e-banking link. I click it and it opens the e-banking page, which sells you the service and in a small corner has a link to the real e-banking application where you can log in and see the big red numbers. I’d say they have a deeper problem than redirecting. They see the bank as a company with its useless propaganda home page and e-banking as a product with its useless propaganda home page and then, the actual e-banking site, somewhere else. They should just have the log in on their home page, like any other on-line service. But I digress.

Back to redirecting. I click log in and it opens, in another window, a web site with a URL that is measured in meters. Long, ugly and scary. I never even thought of bookmarking that because I’m sure it won’t work the second time. So my bookmark is to the previous page. Just today, after a year of using it, I discovered that there’s a nice short well-formed URL for the log in page, something like: bank.com/ebanking/login which immediately redirects to the ugly one. Thanks to the amazing speeds of Switzerland internet connection and today’s browsers I never noticed.

If the bank had just been serving the content through that URL, they would have saved more time over a year than it took me to write this post. Literally. I can’t understand why they don’t do it properly. If they are passing session information, they should use session state on the server side and a cookie. If they have a modular structure where the app is located elsewhere, instead of redirecting you they should use a reverse proxy. It takes a day to configure Apache for such a thing if you don’t know what you are doing.

I’ve been using it for ages to serve Plone sites that are in a subdirectory in a Zope web server which runs in an alternate port, yet the front end is Apache and you are never redirected anywhere. You go to example.com which hits my Apache server and inside makes a request to zope.example.com:8080/example.com and serves you the result, you never leave example.com. Even if you go to the secure version, the SSL part is handled by Apache since Zope is not that good (or wasn’t) at it.

There are cases to redirect someone on a web site. When the content is no longer available or temporarily unavailable. When the user just submitted a form, you redirect if the form was successfully processed to another page that shows the result of the form (the record created or whatever). There are many reasons to do that but that’s for another post.

There’s no reason to redirect on load. Please, don’t do it.

Reviewed by Daniel Magliola. Thank you! Use Other Door picture by cobalt123.