Are you blogging on PH? Get your free blog.
*/
*/

The Official Programmer's Heaven Blog

Theme Graphic
Theme Graphic

The Official Programmer's Heaven Blog

The blog where the Programmer's Heaven team post stuff.

Subscribe

Author

Often knowledgable, sometimes wise, occasionally funny. The Programmer's Heaven blog team post about a whole range of topics, from practical advice on concurrency control to introductions to lesser known concepts such as functional programming. Don't forget to comment on the posts and let them know what you think, like and hate!

Archive

Tags


Delete Blog
Posted on Thursday, January 31, 2008 at 4:28 AM

Divvy up my list? Aye!

I wasn't born in Yorkshire, but I spent most of my childhood growing up there. Yorkshire, a large county in the north east of England, has its own collection of slang, not least including the word "aye", which it appears is appropriate in response to pretty much any situation. Another slang phrase is "divvy up". Basically, this just means to divide a bunch of things up somehow.

These days, I spend a lot of my time writing C#. If I'm dealing with a bunch of things in C#, I'll usually store them in a generic List collection, or some other collection. This got me thinking: how can I divvy up a List in C# into multiple Lists? And that's when I decided to implement the Divvy extension method.

What we're aiming for

Suppose we have a list of scores:
var Scores = new List<int>()
    { 87, 32, 45, 60, 91, 10, 58, 77, 66, 71 };
...

Posted on Tuesday, January 22, 2008 at 7:09 AM

Higher Order Programming Is Easy!

Higher Order Programming is one of those things that to many people sounds weird, magical, mysterious or just too hard for them to be able to do. It's not. If you have ever passed a function or method as a parameter to another function or method, then you have done higher order programming. If you have ever used a function pointer in C or a delegate in C# or some kind of callback mechanism, then you have done higher order programming.

Define it!

We are all used to writing code that takes parameters. We do it whenever we write subroutines, functions or methods. Normally these parameters are data. In higher order programming, one or more of these parameters is code rather than data. That is, you can pass code, functions and/or methods around, just as you can pass data around. That's all there is to it.

Show me an example

Let's look at C#, because the syntax will not be too unusual to programmers in many languages. Suppose we have a List of scores for a test...

Posted on Thursday, January 17, 2008 at 2:55 AM

Why automated testing matters

Test Driven Development is a development methodology that encourages you to write tests before writing the code that is being tested. Following it completely strictly means that you never make a functional change to the code (that is, adding a new feature or fixing a bug) until you have a failing test that implementing the feature or fixing the bug will cause to pass.

For those who are not used to writing tests, such a strict methodology can feel quite daunting, potentially unproductive and perhaps fun-spoiling. I can empathize with all three points of view, but at the same time it's worth trying almost everything at least once to see how it works out (though I'm still not so keen on trying a bungee jump).

In this article I'm going to look at the idea of automated testing more generally. I'll share a couple of my experiences of it, then I'll look at some thoughts for giving it a go in your own environment.

=== Why Automate Testing? ===...
Comments: 7 Tags: Testing, Unit Testing

Posted on Wednesday, January 16, 2008 at 8:27 AM

Sun acquires MySQL

Sun have today announced their plans to acquire MySQL, the company behind the popular MySQL database server. This gives Sun a large stake in the database market. MySQL already has a range of high-profile clients, with some household names including Facebook, Yahoo!, BBC and Nokia.

MySQL is an Open Source and Free Software database, and members of the community will be somewhat reassured by Sun's background. They are the largest contributors of open source code, well known for Open Office and more recently for releasing Java under the GNU GPL. The MySQL VP of Community wrote a blog post to reassure the community about the acquisition...
Comments: 0 Tags: MySQL, Open Source, Sun

Posted on Monday, January 14, 2008 at 7:22 AM

What are the next generation of programmers learning?

Recently I read an article asking, where are the software engineers of tomorrow? Written by a President and Vice-President of the company AdaCore, they lament the spread of Java as a first programming language taught on many Computer Science courses and a reduction in the formal and theoretical background that students are being given.

While I can't say I agree with every word they say (for example, they appear somewhat dismissive of dynamic languages), they certainly have a lot of good points. You certainly don't learn to be a good programmer, developer or architect by learning one or two programming languages. To do that you need to understand the whole stack of abstractions form top to bottom, be aware of many programming paradigms and understand (or at least be aware of the existence of) the theory that explains it...

Posted on Tuesday, January 08, 2008 at 5:30 AM

Today's Topic: Perl's $_ Variable

When we are speaking we often use words such as "it" to refer to the thing we are currently talking about. For example, "My computer has just had a PSU failure. It is on fire." You could say that "it" refers to the current topic, which we assigned in the previous sentence.

Anyone who's read many of my ramblings will know that one thing that interests me is the use of features of natural language in programming languages. What if we could express the idea of the current topic in a programming language, though?

Turns out that is exactly what the $_ variable in Perl is for. It is sometimes also known as the "default variable". If you have read many Perl scripts you will probably have come across things like this:
chomp;
s/\[b\](.*?)\[\/b\]/<b>$1<\/b>/;
print;
The question that people often ask on seeing this is - chomp what? Bind a substitution to what? Print what? A fairly substantial number of Perl built-ins, when invoked a parameter missing, will use the default variable $_ instead. You could re-write the above as:...
Comments: 9 Tags: Perl


corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.
Resource Listings