Posts

Showing posts from October, 2013

Telerik components

I am working on some projects where I am forced to use the Telerik components. They are, without a doubt, the most overpriced junk I've ever had to work with. It pains me that people pay a lot of money for them just because they look pretty. (I am trying to remember ONE issue where the Telerik components were involved and I haven't had to fight them. It's just not coming to mind.)

Avoid boolean parameters

Here's an example of a method in a sim. This started out as a simple method: all days are the same in our simulation, so the method just prints out some activities: void SimulateDay() { Console.WriteLine("Wake up."); Console.WriteLine("Eat breakfast."); Console.WriteLine("Watch TV."); Console.WriteLine("Eat lunch."); Console.WriteLine("Watch TV."); Console.WriteLine("Eat dinner."); Console.WriteLine("Go to sleep."); } Ok, so not much of a life, but this article is supposed to be about programming. :) A new requirement comes up: Sunday should be different. Well, almost; it's actually the same as the other days with a single difference: instead of watching TV, the sim goes to church on Sunday mornings. No big deal, we can augment the method with a boolean parameter: void SimulateDay(int isSunday) { Console.WriteLine("Wake up."); Console.WriteLine(...

Going to college

There's a saying in my country: going to college is not about learning X; it's about learning how to learn, how to study, how to find out things about X by yourself. Which means, in a liberal translation: going to college is for people who don't know how to use Google.

Stop doing this

Pet peeve: I hate micro-management when it comes to code. Yes, it's faster in the short-term but it's a pain when the code has to be changed. (If you don't know that all code has to be changed, you haven't programmed long enough.) In this particular case I have encountered code similar to: var sb = new StringBuilder(); foreach (var p in list) { sb.Append(p.Name); sb.Append(" "); sb.Append(p.Quantity); sb.Append("*"); sb.Append(p.Price); sb.Append("="); sb.Append(p.Value); sb.Append(","); } if (list.Any()) { sb.Remove(sb.Length - 1, 1); } return sb.ToString(); (It's even worse when it's a for loop instead of foreach , but let's not go there.) The problem with this code is that it's extremely easy to get lost in the details. "Oh, I should put spaces around the operations." "Oh, I should add a space after the comma, but then it has to be remov...