Friday, August 29, 2025

Cut / Slash /Burn – The Ruthless Art of Perfecting Your Code...

I'm .NET developer with a long history of team leadership and mentoring. My fundamental belief about software development is best expressed by a quote from Antoine de Saint-Exupery (1900 - 1944)

"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." 

Basically, get rid of everything that is unnecessary. This is a good design maxim for code. Every line of code is a potential bug. Get rid of unnecessary lines of code and reduce potential bugs in your application. The best way to do this is aggressive refactoring using the combined paradigms of SOLID and DRY.

Fortunately, Visual Studio makes this pretty easy. Even before Copilot came along, you could get VS to refactor large chunks of code. I will refactor in small steps, with lots of total solution re-builds after each step. If some refactors seem very complicated or risky, I'll due an interim local commit of my branch before I begin. 

Of course, automated testing makes this less risky. You should have them... 

Wednesday, April 19, 2017

Oh! The Irony ...

If you peruse any decent book or blog regarding "good" coding practices, "naming things properly" is usually near the top of the list of recommendations to follow. This is actually quite important. Most recently, at a recent client's site, I took over the maintenance of a WPF application. It was part of a suite for a medical device the company was developing. One of the many "state" properties that were being used was named "hasManufactured". I was confused by this for reasons below. More importantly, when I asked around, no one else was sure what it meant. The original programmer was long gone.

There are several things wrong with this. First, as a property, it is incorrectly cased. It should have been "HasManufactured". In a more  egregious fashion the other "state" properties in the class WERE properly cased. Was there a reason this one was not?

Second of all, the meaning of "hasManufactured" was completely confusing to me. "Has" as a word, generally means possession of something, or else a state of being. "He has a goat" is an example of possession. "He has been hired" would be a state. But notice that when "has" represents a state, it's usually associated with a verb of some tense. A reasonable interpretation of the meaning of "hasManufactured" was probably "has been manufactured". Of course, everything that was in the manufacturing process was being manufactured, so ...

Finally, after digging around in the code, it appeared that "hasManufactured" was being changed from false to true when someone clicked the "Finalize" button on a particular dialog window. As it turns out, this button was clicked as the final step in the manufacturing process. So a good assumption is that "hasManufactured" really meant "has been through the entire manufacturing process and is ready for sale". A far better name would have been "IsFinalized". (And yes, I did refactor this.)

Which gets me to the real point of this post. "Object Oriented Design" and "Object Oriented Programming" are both lousy names.

I've been doing .NET Framework programming for over 15 years at the time of this post. Not once have I ever coded an object. In fact, Visual Studio doesn't create object files, it creates class files.

The following code is syntactically correct and declares a class:
public class MyClass() {}
However, this next statement is syntactically incorrect and it has a completely different meaning and result in c#:
public object MyObject() {}
In the first case, an empty class (no members) is being defined. In the second case, the only reasonable meaning is someone mis-coded a method in a class that was supposed to return an instance of the object class.

Note the distinction here identified by the difference in syntax. We developers are NOT doing Object Oriented Programming. We are doing Class Oriented Programming. And we are doing Class Oriented Design. We don't use diagramming tools that provide "object" diagrams - they provide "class" diagrams. Unfortunately, I don't anticipate a successful #hashtag campaign to change the name of the paradigm ...

So here we have an entire industry that recommends naming things properly that has incorrectly named its industry.

Paraphrasing Colonel Kurtz: "Oh! The Irony..."

Sunday, April 16, 2017

My first Xamarin app ...

I just finished my first Xamarin app and published it to  GitHub. It can found here.

I've certainly had my issues with Xamarin. I have an earlier post that's quite a rant. It turns out that if you want to create a "library" assembly to use in a Xamarin PCL, you seem to need to create a .NET Standard 1.4 (or less?) library. Then you can reference it in a PCL assembly. Who'd a thunk it...

Nevertheless, the emulator I selected worked quite well, and didn't require any configuration - though granted my app is very tiny. This app is just a proof-of-concept app to prove the feasibility of a bigger app I'll be working on to commit to the stores.

Hopefully, my experiences with Xamarin will improve. While it's been uncomfortable, it's still a lot more successful than my even more painful experiences with Cordova and NativeScript.