10 (unusual) ways to use 140 characters

2

Posted on : 20-11-2009 | By : matteosp | In : Fun, Links, Miscellaneous, Uncategorized

twitter

I recently became a twitter user, and I immediately got addicted. I really have the sensation that twitter is extremely powerful, even if I still don’t exactly know how. So, while I think a little more about what can I do with it (as tool/platform for my job, I mean), here some fun things you can do with the 140 chars of a tweet:

140 chars…. not too bad eh?

Even more portable life

0

Posted on : 18-11-2009 | By : matteosp | In : Software rocks, Tools

portableapps.com

Recently discovered there are interesting new entries within my loved portable apps:

  1. Skype, never thought it could ever go portable.
  2. TeamViewer, one of my favorite collaboration and remote support tools. Really powerful, give it a try.
  3. 2X Client, RDP remote client with interesting features.
  4. Google Chrome (beta 4), personally I found that a portable browser is a must.

For the complete list of portable apps give a look here. Notice that almost everything is free.

Simple parallel programming

0

Posted on : 18-05-2009 | By : matteosp | In : .Net Programming, ParallelProgramming, Threading

While waiting for Parallel Extensions (wikipedia), that will be shipped with next .Net Framework release, I designed a couple of class that allow to quickly (and easily!) write code that make use of multi-threading and, therefore, speed-up many tasks. What I show here is a simple class able to collect pieces of code (in form of delegate) to be executed concurrently, and parallelize and synchronize the execution. The main goals I kept in mind while realizing the solution were:

  • Ease of use, minimal requirement in terms of multi-threading skills
  • Allowing single-threaded code to be ported to multi-threading with few changes
  • Code readability
  • Support for exception management

Here what I came up with:

The API exposes one class, ParallelExecutor, and one interface, IExecutionResult (plus a generic specialization of the interface and the necessary implementations). Before seeing the internals of the solution, I want to show the ease of use of the API.
Let’s start with this example:

   1:  void SerialExecution()
   2:  {
   3:      Uri uri; int value;
   4:  
   5:      CallWebService(uri);
   6:      PerformComputation(value);
   7:  }

CallWebService() and PerformComputation() represent the most classic example of methods that can (and should!) run in parallel as they perform respectively I/O and CPU computation. But usually programmers haven’t enough confidence with multi-threading execution and synchronization to do things in the right way. In any case they shouldn’t care about this stuff, they should focus on coding logic, and not on coding about how the logic get’s executed. Let’s see how ParallelExecutor comes in help:

   1:  void ParallelExecution
   2:  {
   3:    Uri uri; int value;
   4:  
   5:    ParallelExecutor executor = new ParallelExecutor();
   6:  
   7:    executor.Add(CallWebService, uri);
   8:    executor.Add(PerformComputation, value);
   9:  
  10:    executor.WaitAll();
  11:  }

Not too bad, right? With a couple of lines I got the two methods run concurrently. This is pretty simple: the Add() method takes as arguments the method to invoke and the arguments of that method. The WaitAll() causes the calling thread to wait for all the methods passed to Add() to complete. Take a (partial) look to the ParallelExecutor definition:

   1:  public class ParallelExecutor
   2:  {
   3:    public IExecutionInfo<object> Add(Action workItem)
   4:    public IExecutionInfo<object> Add<T>(Action<T> workItem, T arg)
   5:    //overloads for other Action versions 
   6:  
   7:    public IExecutionInfo<TResult> Add<TResult>(Func<TResult> workItem)
   8:    public IExecutionInfo<TResult> Add<T, TResult>(Func<T, TResult> workItem, T arg)
   9:    //overloads for other Func versions 
  10:  
  11:    public bool WaitAll():
  12:  }

As you can see, method to be parallelized are passed to Add() in form of variations of Action and Func generics delegate (there are also overloads that take MethodInfo and the standard Delegate). But what about the Add() return type, IExecutionResult? Let’s see the interface declaration:

   1:  public interface IExecutionInfo
   2:  {
   3:    object[] Args { get; }
   4:  
   5:    Exception Exception { get; }
   6:  
   7:    object Result { get; }
   8:  }
   9:  
  10:  public interface IExecutionInfo<TResult> : IExecutionInfo
  11:  {
  12:    TResult Result { get; }
  13:  }

At every invocation of the Add() method an instance of a class implementing IExecutionResult is created, and its Args property is filled with method invocation arguments. After the invocation completes, the Result and Exception property are filled too (in both case, if any). And the magic of generics allow the code to be type safe. So, returning to the example, if CallWebService() has a return value and if you want to check for exceptions, you can write:

   1:  void ParallelExecution
   2:  {
   3:    Uri uri; int value;
   4:  
   5:    ParallelExecutor executor = new ParallelExecutor();
   6:  
   7:    IExecutionInfo<int> execution = executor.Add<Uri, int>(CallWebService, uri);
   8:    executor.Add(PerformComputation, value);
   9:  
  10:    executor.WaitAll();
  11:  
  12:    if (execution.Exception != null)
  13:        ManageException(execution.Exception);
  14:    else
  15:        Console.WriteLine("Result: {0}", execution.Result);
  16:  }

Another couple of properties exposed by ParallelExecutor allow you to control when the execution starts (immediately after Add() or when WaitAll() gets called) and the aggressiveness of the threading policy (one new Thread for every method passed to Add() or threads got from ThreadPool).

Obviously this is a very simple implementation, far away from what Parallel Extensions will be. But its simplicity may suite well some implementation with no heavy requirements.

Source Code.

Great ideas from the web

0

Posted on : 12-09-2008 | By : matteosp | In : Links, Software rocks, Tools

A wonderful week for one of my greatest passions: software ideas that rocks. In few days I discovered these fantastic two:

1) Ubiquity, a revolutionary way to interact the web in a natural way. Take a look at this impressive video and get it here. Oh… obviously: it’s for Firefox.

2) Dropbox, what SkyDrive should (and could) have been but is not. Easily and quickly synchronize your files with different PCs or access them directly from the browser.

The entire world wasted a lot of words in past two years about Web 2.0. I think that we shouldn’t care about version numbers, instead we only should care about great ideas (like this one, also from Mozilla Labs).

via Ale & Pietro.

Portable life

1

Posted on : 05-09-2008 | By : matteosp | In : Links, Miscellaneous, Software rocks, Tools

It’s a long time I’m a big fan of portable apps, and – for at least two good reason – I use them not only from the USB pen, but even from system drive. First: as a developer I’ve a fresh OS installation relatively often and a simple copy is far smarter than many installations. Second, I can directly (via a network share) run portable apps from different machines (including virtuals I host). Not to tell the fact that settings and preferences always follow the apps and that my registry remains a little bit cleaner…

I wanna ensure you that, once you get used to this, it’s hard not to have it. So I started to collect the portable version of everything I can find, and currently my “Portable Apps” folder contains more than 50 apps. Every day I’m more convinced that almost everything should be portable, also (or especially) things like Visual Studio or other complex applications. I don’t want to list every single portable app I use, but let’s sat that…

I surf the web with Firefox Portable Edition and I read my email with Thunderbird Portable Edition and my feeds with FeedReader. I do IM with PSI (a jabber client – note that many jabber servers are server-side integrated with gTalk, Yahoo Messenger, MSN and others), I download with Free Download Manager and uTorrent, I work on FTP servers with FileZilla Portable.

I use Foxit Reader for PDF documents, I view/edit text files with Notepad2, Notepad++ Portable and I take notes with Dark Room (see also Tools for writing and the way I write). I’m currently evaluating xMind for my mind maps.

I watch videos and movies with Videolan Portable, manage and look my pictures with Fastone, sometimes edit them with GIMP Portable. I listen web radio (check Radio SNJ!!!!) with RadioPlay and my music with CoolPlayer+ Portable.

And, of course, I work with Reflector (can’t not to cite), Snipper Compiler, a lot of stuffs by SysInternalsSqlDbx, and others.

I’m still waiting (may be dreaming) for VMware Workstation Portable, Visual Studio Portable, Office Portable, Photoshop Portable…

Take a look also here:

How I got Started in Software Development

1

Posted on : 30-07-2008 | By : matteosp | In : Fun, Miscellaneous, Programming

I had the great pleasure of having been tagged by Adrian. So… it’s my turn:

How old were you when you started programming?

In 1994, when I was 16 and I was at the high school. But I must say also that at the age of about 10 year a “played” with BASIC on a Laser 500, something similar to a Commodre 64.

How did you get started in programming?

… in those days I learned Turbo Pascal, and I used it to solve not too complex math and physics problems.

What was your first language?

As I said, the very first language was Pascal. But, as a professional, I consider my first language to be Visual Basic 6. It is for sure the language that made me falling in love with programming.

What was the first real program you wrote?

At the end of a one year programming training I build a RSE – really simple ERP ;-) – for demo purposes. A WinForm application over an MS Access database. Presentation Layer e Business Logic were mixed up in the Visual Basic 6 forms, but I think here I wrote my first Data Layer.

What languages have you used since you started programming?

In order Basic, Turno Pascal, C++, Visual Basic 6, Java, PHP, ASP, JavaScript, VB Script, C#, Visual Basic .Net, Python.

What was your first professional programming gig?

In Brain Force, the company I’m still working for. 6 years ago.

If you knew then what you know now, would you have started programming?

I love programming: it consume a lot of resources but gives back a lot of satisfaction. But I would have choosen something else.

If there is one thing you learned along the way that you would tell new developers, what would it be?

Start from the theory and with the doc. Ever. Ever!! And pay attention to who wrote what you read.

What’s the most fun you’ve ever had … programming?

An ORM. I’m really proud of it.

Now, let’s tag someone else…

The final truth about OOP

0

Posted on : 14-04-2008 | By : matteosp | In : Programming, Quotes, Software sucks

My guess is that object-oriented programming will be in the 1980s what structured programming will be in 1970s. Everyone will be in favor of it. Every manufacturer will promote his products as supporting it. Every manager will pay lip service to it. Every programmer will practice it (differently). And no one will know just what it is.

T. Rentsch

The more I read these words, the more I’m convinced this is one of the more accurate prediction I’ve heard about in programming. I feel it so… real.

via Booch, Grady. Object-Oriented Analysis and Design with Applications, Second Edition. Boston: Addison-Wesley, 1993. Link.
via West, David. Object Thinking. Redmon: Microsft Press, 2003. Link.

Quiz #3

8

Posted on : 27-02-2008 | By : matteosp | In : C#, Quiz

Take the following snippet:

public class Foo
{
  // add code
  public static int MethodOne() { return 0; }
  public static string MethodTwo() { return string.Empty; }
}

public class Program
{
  public static void Main()
  {
    try { Foo.MethodOne(); }
    catch (Exception ex) { Console.WriteLine(ex.Message); }

    try { Foo.MethodTwo(); }
    catch (Exception ex) { Console.WriteLine(ex.Message); }
  }
}

and add the code necessary (you cannot modify in any way MethodOne and MethodTwo) to make both method invocation throw an exception.

Two Bites Are Better Than One

0

Posted on : 18-01-2008 | By : matteosp | In : Fun

This amazing AD was published in 1978 30 years ago, just one year before I was born. From a technology point of view I’m a dinosaur…

Two Bites Are Better Than One.

Source: 10 Incredible old computer ads.

Shouldn’t downlaoding be easy?

0

Posted on : 23-10-2007 | By : matteosp | In : Software rocks, Software sucks, Tools

It’s 2 days I’m trying to get Visual Studio 2008 beta 2, a true pain.

Both the two download manager proposed as plug-ins by msdn site (an ActiveX for IE and a Java applet for firefox) don’t work. From two different computers, so is not my problem. I suspect the reason is the web server replying with a 302 HTTP code (temporally moved) to the first request, but I’m not sure.

Ok, I said to my self. It’s time to get a download manager. And I started surfing Softpedia looking for something freeware. The first I tried was VisualVGet. The maximum speed I was able to obtain over 12Mbits DSL line was 5Kb/s. I tried to tweak it a little bit, but nothing happened. Uhm… I need the beta 2 before the final version is released…

Then I remembered of GetRight, I used it a lot in the past. Isn’t free, but the trial period should be enough, I thought. Quickly downloaded and installed. But never been able to use it. The only thing I was able to do was seeing the process getright.exe starting, and shortly terminating. No windows, no alert. No messages in event viewer. A software I will never buy.

Finally, again via Softpedia, I found FDM (Free Download Manager). That is what a program of this kind should be: easy. I learned to use it in about 30 seconds, configured in 15 and, first of all, downloaded Visual Studio in a couple of hour, having the download speed at 350/400 Kb/s, as expected. And… if not clear from the name, it’s free!