Saturday, May 3, 2008

I've been spending alot of time recently on learning to use Ubuntu, as well as some dynamic "P*" languages like Pyton and PHP.
I must admit after spending so long in the world of the strictly staticly typed CLR, the switch to a language with such a lenient type system what quite a paradigm shift. My initial thought was something along the lines of, "OK, so you have classes with multiple inheritance. Cool. But tell me, what's the point of a class when you can shove whatever data you want into it? What's the use of a Point2D class when the x coordinate could be a collection?"
Misunderstandings aside, though, Python does offer one thing that I have recently fallen in love with. So much so that I decided to try my hand at pulling it off in C#. Not surprisingly, the actual functional code very similar, but it's just another testiment to the simplicity of Python's syntax vs that of other static languages.

/*
* test.cs
*
* A simple test of what list comprehension would be like in C# 3.0.
* Demonstrates performing the function ƒ(x) = (x+2*x+x/2)
* on a set of datapoints (4.2, 5.3, 6.2).
*/

namespace Test {
using System;
using System.Collections.Generic;

///
/// Small program intended to demonstrate manual (non-
///

static class Program {
static void Main() {
/*
* Python code for this code would be best approached with
* list comprehension one-liner:
* [x+2*x+x/2 for x in [4.2,5.3,6.2]]
* C# requires the helper function.
*/

var result =

new List(new float[] { 4.2f, 5.3f, 6.2f }).Map(x => x+2*x+x/2);

foreach (float x in result)

Console.WriteLine("{0:f4}", x);

Console.ReadKey();
}
}
static class Extensions

{

public static IEnumerable Map(this IEnumerable data, Func predicate)

{

foreach (T item in data) yield return predicate(item);

}

}
}

/*
* Curious about how this would be done in C# 2.0?
*/
namespace Test {
using System;
using System.Collections.Generic;

static class Program {
static void Main() {
// ugly, ugly, ugly.
IEnumerable result =
Map(new List(new float[] {4.2f,5.3f,6.2f}),
new MapPredicate(Calc));
foreach (float x in result) {
Console.WriteLine("{0:f4}",x);
}
}
static float Calc(float x) {
return x+2*x+x/2;
}
// using Lists, just to make it easy. Could be IEnumerables.
static IEnumerable Map(IEnumerable data, MapPredicate predicate) {
List items = new List(); // just to make it easy
foreach (T item in data) {
items.Add(predicate(item));
}
return (IEnumerable)items;
}
delegate R MapPredicate(T val);
}
}

Saturday, April 5, 2008

Python/Ubuntu Love

My current financial situation has cause quite an uprooting of my normal daily schedule. The past week as gone like so:
Mon-Tue: Sick. Diarrhea. Gross, I know. Spent most of my time between the back porch for fresh air and the bathroom.
Wed-Thur: Not much at all. Spent alot of hours in front of my desktop playing Final Fantasy 7 for the sake of mind-numbing nostalgia.
Fri-Present: Friday I borrowed my dad's laptop after spending several hours at his office reading Eric Lippert's blog. Took it home, popped in Ubuntu Gutsy Gibbon, and decided I needed to learn Python.

Learning Linux has been quite an adventure for me. Ubuntu's mantra of being "Linux for human beings" is quite appropriate. I would like to consider myself a well seasoned geek, but after spending several hours with Knoppix at ECTC, the difference in usability (at least for me) is quite dramatic. Simple, streamlined interface. Help all over. Just great stuff.
At first I was somewhat skeptical about the limited collection of apps it ships with--Knoppix as a stand-alone LiveCD has just about everthing you can imagine--but I soon learned how easy it is, given a reliable internet connection, to just drop in just about anything you need.
One rule of thumb I stick to, though: If you can't get it through a package manager, stay away. Unless you're a developer like me and have to go through subversion and the like for the necessary libraries for developing on Linux, that seems to be pretty much a universal truth.

One note, though, that I find rather odd is that I still have trouble installing simple things like Flash and Java. One of my first goals when I booted up the system was, like most users, customize my browser to my liking. Firefox, of course is totally stable on this build, but does not ship with plugins for Flash or Java. Why this decision was made by Canonical is far from me to determine, but again, the "Linux for humans" slogan loses a bit of it's appeal when simple things like this are skipped. I can only hope this problem is remedied by the 8.04 "Hardy Heron" release this month.

As far as the Python pursuit goes, at the moment it's slow-going. Like with most langauges, I have a hard time learning it without some sort of goal in mind. I've got one, a GUI front end for GCC, but that requires a GUI designer. With that said, I think I may have fount my IDE of choice for the time being: SPE. It's UI is similar to that of Eclipse and Visual Studio, but does not include a UI desiger. For that I suppose I would be willing to learn wxGlade, which is apparently the UI Designer required for this product. The lack of a UI component of a base library for a language is something that is foreign to me, given my experience in .NET.

All in all, a rather boring, but mostly productive week.

EDIT: I just learned from the Ubuntu beta page that the CFS has officially been added to the 2.6.24-12.13 kernel. If I wasn't limited to the 250 some-odd Mb of swap file space, I would download the beta now.

Wednesday, December 19, 2007

He made Bill Gates a grilled cheese sandwich

Today I had lunch with the man that Bill Gates bought Word from.
And I got fired.

What a day.

Monday, November 26, 2007

The other 40%

It seems Jeff Atwood's post on the Two Types of Programmers, as well is it's mother post, has missed a very important niche in the development community: The Microsoft Fanboys.
These are the ones that jumped at the opportunity to develop with MONO, and competed in the Code Project's Race to Linux. The developers who read the C# 3.0 Language Specification just ot improve the CLS compliance of their code. The developers who where hired on to those measly "internal" jobs with the sole purpose of upgrading the companies legacy code to .NET, and convince the company they need MSDN just so they can come home at night and install nightly builds of Windows Server, SQL Server, and Visual Studio in hopes of keeping that company ahead of the curve.
The detail that both Jeff and Ben leave out is the propensity of many Microsoft developers to be just as passionate and dedicated as any Open Source dev.

Shocking Comment #1: I like programming and really enjoy ASP.NET. I think it's neat and fun and interesting and cool how you can go from literally nothing to having a data-driven web application that can be used by people around the world in an amazingly fast amount of time. Furthermore, I want to spread that enthusiasm to folks.

I have an immense amount of respect for anyone who calls themselves "Open Source" and yet does their best to evangelize a Microsoft product. I think it is especially a great testament to what Microsoft has created in .NET when open source advocates like Jeff actually call for more open source .NET projects like MONO and others.

Shocking Comment #2: [The alpha-geeks] get all excited about the latest Linux distro or AJAX toolkit or distributed SCM system, spend all weekend on it, blog about it… and then are confounded about why they can’t get their office to start using it.

I just think it's a sad reality that many of the best software out there is kept behind closed doors for this same reason. The sad facts are stated clearly above. The open source guys can get their companies to use any open source tools, so the best open source doesn't make it into the enterprise, while the fanboys are constantly innovating in the enterprise, but are bound by law in some cases to keep their technology proprietary.

It's a simple but sad state of affairs that in my own cynical mind has no hope of changing any time soon.

Wednesday, October 31, 2007

VB. It's good for something...

For better or worse, I spend a lot of time trying to explain real life situations in code.
Below is the thought process of Paul McCartney when writing "Let it Be".

Public Class Beatles

Private hardship As New Death(Of Mother)
Protected help As Mother
Private WithEvents life As New Paul()

Public Sub New()
If help Is Nothing Then
life.Experiece(hardship)
life.Experiece(New Hour(Of Darkness))
End If
End Sub

Public Sub Sing() Handles life.TimeExperienced
While life.Contains(hardship)
Me.help = hardship.Help
Whisper.Words(Of Wisdom)(help)
life.RecoverFrom(hardship)
End While
End Sub
End Class

Class Trouble

End Class
Class Death(Of T)
Inherits Time(Of Trouble)

End Class

Class Time(Of T)

Private _help As Mother = New Mary()
Public Property Help() As Mother
Get
Return _help
End Get
Set(ByVal value As Mother)
_help = value
End Set
End Property
End Class

Class Hardship
Inherits Time(Of Trouble)

Public ReadOnly Property Cause() As Time(Of Trouble)
Get
Return New Darkness()
End Get
End Property
End Class

Class Darkness
Inherits Time(Of Trouble)

End Class

Class Hour(Of T As Time(Of Trouble))
Inherits Time(Of Trouble)
End Class

Class Times(Of T)
Inherits List(Of Time(Of T))
End Class


Class Life(Of T)
Private times As New Times(Of T)

Function Contains(ByVal time As Time(Of T)) As Boolean
Return times.Contains(time)
End Function
Sub Experiece(ByVal time As Time(Of T))
times.Add(time)
RaiseEvent TimeExperienced()
End Sub
Sub RecoverFrom(ByVal time As Time(Of T))
times.Remove(time)
End Sub

Default Public ReadOnly Property Time(ByVal index As Integer) As Time(Of T)
Get
Return times(index)
End Get
End Property

Public Event TimeExperienced()
End Class
Class Paul
Inherits Life(Of Trouble)
End Class


Public Class Whisper
Shared Sub Words(Of T)(ByVal m As Mother)
Console.WriteLine(m.Advice)
End Sub
End Class

Public Class Mother

Private _advice As String
Public Property Advice() As String
Get
Return _advice
End Get
Set(ByVal value As String)
_advice = value
End Set
End Property
End Class
Class Mary
Inherits Mother
Public Sub New()
Advice = "let it be"
End Sub
Public Overrides Function ToString() As String
Return Advice
End Function
End Class

Public Class Wisdom
Inherits Knowledge
End Class
Public Class Knowledge

End Class


Public Class Hit
Public Shared Sub Create()
Dim b As New Beatles
End Sub
End Class

Thursday, October 25, 2007

Wanted:

Programmer.
Must work be able to work unreasonable amounts of time, on impossible deadlines, with insufficient resources, inadequate compensation, conflicting orders, and be have ability to read boss's mind and accept responsibility for everything that goes wrong.

Wednesday, October 3, 2007

Finally! Someone with a brain!

This post should be put on a pedestal and bowed down to by millions.
I think every developer on the planet that has had to dip into legacy code has been in the same situation as I was a month ago: "It's my fault that the stored proc sent out 15,000 of the same email? How was i supposed to know it was in a while loop? The loop itself was nested 300 lines deep with 300 lines within it! It took 10 seconds of scrolling to get from the declaration to the end!"