Tag Archives: tips

Friday coding contemplation

I haven’t really been to roads end with this one, so bear with me if it doesn’t quite make sense.

When coding, I usually like to keep my objects as immutable. But on the other hand I really like the verbose way of initializing objects with Object Initialization. Of course there are ways around this, like named parameters, or just the good old naming variables correctly.


  var p1 = new Person {
    FirstName = "Monkey",
    LastName = "Business",
    Age = 42
  };

  var p2 = new Person(
    firstName: "Monkey", 
    lastName: "Business", 
    age: 42
  );

  var p3 = new Person()
    .SetFirstName("Monkey")
    .SetLastName("Business")
    .SetAge(42);

Where the Set-methods looks like the following.


  public Person SetFirstName(string firstName)
  {
    FirstName = firstName;

    return this;
  }

  public Person SetLastName(string lastName)
  {
    LastName = lastName;

    return this;
  }

  public Person SetAge(int age)
  {
    Age = age;

    return this;
  }

While this doesn’t make the objects immutable at all, it does open some other benefits. From time to time I tend to really dislike properties because they are easy to misuse. I myself don’t have a right or wrong answer, but to me they should be lightweight accessors and not perform a whole slew of stuff. If you are in that position a method might be good.

I guess the gist of this is that there are ways of doing things which we might forget. And while we love our fluent APIs, we are quite crappy at actually creating and using them for ourselves when not served via a library, framework or something. But all we really have to do is return this;.

What’s your flavour?

Tagged , ,

.gitignore

I don’t think it matters, any tool you use will create a bunch of support files for whatever reason it has. Settings, tracking, state… There is always something. Especially if working with Visual Studio and Git-TF or Git-TFS, make sure your .gitignore file is in order. Realizing what that means, you probably do not want to write your own, so there is one created for almost all environments.

.gitignore on GitHub saves your life.

Update: I got a tips on an additional gitignore resource called GitIgnore.io which generates .gitignore files according to your spec. Perhaps you need to include both Windows and OS X and several editors? This is the tool for you! Thanks @sodper.

Tagged ,

Do not miss this! #imtellingyou

Just a quick update, since there is something you do not want to miss this week. Marcus Hammarberg is doing a series this week on what he has been up to for the last decade(?) or so, before retiring the material in current form. Brilliant guy and it is all free, so if you have the time – make sure you go to at least one of the sessions.

Read more on his blog about “I’m telling you for the last time“.

A new traveler

Also, there is a new globetrotter. A guy from UK is adventuring Corey Haines style around the globe to see places, meet people and code to learn and master his profession. Follow him and check it out. Or even, could you help him help you? Check out Andy Waites blog for more info. At the moment he is poking around North America.

Tagged , ,

Asus bloatware guide

For some reason I had to borrow my wifes computer the other day. I was just stunned at how slow it was and took a peep what programs might be installed. It’s a fairly standard Asus, preinstalled and been around for a couple of years but not used that much.

Anyway, she is not the type that installs a program, so I was blown away by the amount of crap that was in there. I didn’t know all of the stuff but the names gave me a pretty good hint. Then there were some that I had to know more about and that’s when I found this list:

Asus bloatware guide

A neat list, not exactly up to date but most is still relevant. Once I got rid of all crap things just started flying on her computer as well!

Tagged