Channels ▼

Christopher Diggins

Dr. Dobb's Bloggers

Duck Typing and the Go Programming Language

November 24, 2009

I was reading up on the Go programming language, specifically the language design FAQ (http://golang.org/doc/go_lang_faq.html) and it got me thinking again about duck-typing (signature based polymorphism). 

First, I have to strongly recommend that all programmers carefully read the Go language design FAQ. It is a glimpse into the kinds of issues that programming languages designed for the future are going to be doing in the face of rapidly increasing parallelism. The people designing this language, really know what they are doing in many respects, especially when it comes to concurrency.  

One thing about the FAQ that intrigued me was the level of excitement over signature based polymorphism (duck-typing). This is clearly one of the most exciting features from the point of view of the language designers (who are also using the language extensively). 

In the past I talked myself out of using duck-typing for Heron because I liked the explicit information carried in a class about what it is intended use is for. I was also scared of the possibility of accidentally using classes where the behavior did not match what was expected. Think of the case of a FIFO queue versus a LIFO queue. 

Now that I think about it though, I think that perhaps I was just being overly cautious. I realize that I frequently using C++ templates as a poor-man's duck-typing. 

Perhaps I should throw caution to the wind, and embrace duck-typing fully? Or maybe I should take a middle of the road approach and provide a form of explicit duck-typing via a duck-typing coercion operator. E.g. "MyFunction(Dog as IInternetUser)". 

So what are your thoughts, would you want duck-typing in a language intended for engineering large-scale complex software developed by big teams of developers? Would you like a "duck-typing" coercion operator, and if so what would you name it?

Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 


Video