typemismatch

just a projection of my own imagination

  • You are here: 
  • Home
  • 2008 April

Duck-typing is great! but also bad.

Posted on April 21st, 2008

I haven’t yet posted my work on PHP so this is a little out of context however since it applies to many popular languages I’m just going to go ahead and post :)

Here is a brief description of what duck typing is – basically slang but a very nice feature of various programming languages. I personally like it and I suspect most others do simply because it saves key strokes, after almost 10 years of c# programming you get very tired of double declarations.

So I have recently been doing a lot of work with PHP and discovered a disadvantage of duck typing. Although the compiler and runtime environment may know what type a variable is, you as a programmer might not! This might not seem like a big problem if you wrote the entire program but if you’re working with someone elses code or writing plugins/modules for existing systems, you’ll find this kinda hard. If you see a variable called $params being passed into a function you could “guess” it is an array but it might be some custom class.

I use a nice PHP IDE (phpEd) and real debugger so I can get the information quickly if I want but still, it raised yet another issue in trying to understand what code is trying to do.

-c

Tags: ,
Filed under Software | No Comments »