My professional career until now (spans barely 8 years), has been mostly “C#”ish. I liked the language when I started working with it, and really enjoyed staying within the Visual Studio editor. While I was working earlier in my career, I did find interest in reading several blogs about being a better programmer as a whole. The word “polyglot” reverberated in many such well thought blogs. I did understand at the point that having exposure to many languages will equip me better in my work. But here is my honest take on it now that I have spent some reasonably sizable amount of time with a language.
You got to know a particular language well first. For me it is undoubtedly C# as it stands. Once you have that under your sleeves, when you start exploring other languages you learn them in a different way than you would have learnt if you had not mastered a language. It becomes just involuntary that you start comparing features of this new language to the language of your forte. And with this the benefits are two-fold, you learn the new language faster, and you find better ways of solving problems in your mastered language. I think the second point is really exciting for me as I venture on learning new languages and paradigms. For some limited time now, I have worked on Java professionally. I have taken a stab at Scala and Haskell during my personal time although it is not usual to find these 2 languages easily in mainstream application development. The best way to learn languages is to solve some really common problems in computer science. I like the Producer-Consumer problem as it highlights usages of collections and threads which form the biggest chunk of the stuff we use. Below are C# snippet juxtaposed to Java snippet. Spot 6 differences to win a free trip to Goa .
public class PCQueueCharp | public class PCQueueJava |
And here is a beginners implementation in Scala
class PCQueue(capacity:Int)
{
val queue = new mutable.Queue[ITask]()
val syncObject = new AnyRef
def addTask(task : ITask) : Unit =
{
synchronized
{
if(queue.length == capacity)
wait()
queue += task
notify()
}
}
def removeTask() : ITask =
{
var task : ITask = null
synchronized
{
if(queue.length == 0)
wait()
task = queue.dequeue()
notify()
}
return task
}
}
The idea is to improve this class in Scala to make it more “Scala”ble in a later post.
No comments :
Post a Comment
Leave a Comment...