Virtually the best blog on the web!
Posts tagged Programming
Bjarne Stroustrup’s interview about C++
Dec 5th
MIT Tech Review has this article about Stroustrup’s views on current state of C++, programming etc. Stroustrup, the C++ inventor, seemed to answer quite candidly.
One particular comment is interesting.
That said, C++ has indeed become too “expert friendly” at a time where the degree of effective formal education of the average software developer has declined. However, the solution is not to dumb down the programming languages but to use a variety of programming languages and educate more experts. There has to be languages for those experts to use–and C++ is one of those languages.
It’s true that C++ is actually expert friendly and is some times intimidating to a newbie programmer. It’s been a while since I did “real” object-oriented programming in C++, but whenever I tried to use it, I felt like it had too much power. This quote from Stroustrup himself puts it succintly.
It’s easy to shoot yourself in the foot with C. In C++ it’s harder to shoot yourself in the foot, but when you do, you blow off your whole leg.
There are endless articles about the power of C++ and how it makes it difficult to use. I think for large projects that are not performance-critical a language like Java might be more beneficial.
On a side note, my favourite language these days is Python. Obviously, it’s ten times slower than C++, but can get the work done with 100 lines written in 10 minutes.
Learning a New Language: Python
Jun 15th
I have used Perl for my scripting needs for a long time. The first time, I used it, I was totally blown away by its power, and flexibility. The regular expressions, dynamic typing, endless CPAN modules, and of course the geeky (read phreaky) syntax. Later, I got enamoured with it, learnt more advanced features, and wrote a few articles for the Linux Gazette as well.
Then, I wrote a web statistics package in perl. It started with building an innocent counter for my web-site and developed into a full-blown web stats package. I also wrote a some-what complicated set of scripts to build my web-site. Though, I liked the “More than one way to do it” paradigm, the syntax sometimes irked me. Some of the features (like OOP, those funky references) always looked like an after thought rather than good design.
I still use Perl for all my scripting needs, but It’s always a pain to write big piece of software in Perl and maintain it peacefully.
Here in HP, in my group, most of the scripting (for setting up testbeds, running benchmarks) are written in Python. I thought this is a good time to learn a new language. It took me a day to read through the excellent Learning Python book, and I am off to some coding. It’s a refreshing change, especially for someone coming from perl background. The best way to sum it up is that It’s as powerful as Perl with out all the wierd baggage.
I have only scratched the surface, but I am very impressed with its syntax and semantics. Most of the features are very natural, and the consistent semantics for data structures is cool. It has all the usual scripting baggage: dynamic typing, quick coding, extensive libraries, regular expressions etc.
Let’s see a cool, some-what advanced feature called mapping. This feature makes Python a little closer to functional programming languages. Often, when you have large data structures, one thing you want to do is to iterate over all the entries, and do something with each of the entries. Usual way is to use a for loop to go over all the entries. For ex. to increment each number in a list by 2
mylist = range(1, 10) for i in mylist: mylist[i] = mylist[i] + 2
Now, this is all good, but what if you want a different operation, or a complex operation. Naturally, you would think of a function that can iterate over all the entries. There you go !
def add(i):
return i + 2
mylist = range(1, 10)
print map(add, mylist)
How easy is that ! For those who don’t know Python syntax, def creates a function, and the map keyword allows you to apply a function to all entries in a list or a tuple. For more fun, read about List Comprehension and a great use of it to create SQL one-liners.