Monthly Archives: August 2015

Having a Complete Lack of Style is a Good Thing

In this era of open source projects I’m more than a little surprised that official code styles still exist at companies. After all, on any given day I or any developer could find themselves diving into company code, AngularJS’s code, Bootstrap’s code, or any one of the innumerable third party libraries that end up in code bases these days. With all these differing contributors we developers can and do end up plumbing through a wide array of code styles thereby making adhering to one style for one part of the code nothing more than busy work. With consequences.

Through the ether I can hear an argument for, “I can tell what code base I’m in by how it’s written,” and I don’t care about that. I also think we’d be better off as teams if no one cared. Remember, all code in your project is you and your team’s responsibility whether it came from someone in house or is something off of GitHub or even if it came from a StackOverflow post. I would hope and expect a professional developer to be able to read the code where ever it came from and the casing of variables or where they are placed will be of no consequence to their ability to perform their job.

In all my 12 years of doing professional development, the only thing that style guides have ever really been good for taking the teeth out of code reviews. With style guides, the focus of code review observations often become about how something is or isn’t commented per the style, or variables don’t have the right naming convention per the style or something else inconsequential is out of place per the style and what’s missed is (true story) the code itself doesn’t even compile because the author coded foo(“bar”, , 42);. That function with a missing parameter made it through review I’m sure in part because the code around it looked up to style. Company style guides are a distraction of low hanging fruit for developers to grab and “contribute” to the project instead of doing a service to the code by picking it apart and looking for actual problems.

Then there’s blindly following the guide because “That’s what we do” and at this time I find myself at a great point to bring up goto. Early on in my computer science education I learned we don’t use goto. It’s bad bad bad and so we just don’t don’t don’t. I followed that guidance blindly for years until rather recently I saw some sample code from Microsoft. In it goto was used to skip creating additional COM objects when the initialization of one of the required objects failed. By skipping, the goto brought the flow to the cleanup of the objects that had been made. Well that’s a great use! Why run code that doesn’t have a chance at succeeding anyway? Sure there’s other ways to deal with this type of failure but my point here is, the goto based solution was valid.

Edit 5/27/16: I had something here about just needing well organized code but I’ve had to admit to myself that my motivations for well organized code were misguided. I had also said you didn’t need meaningful variable names cause I was waxing academic so I’m going to change that stance to for corporate code, ya need rare strings for quick grepping. Origination to the point where a rare string can be searched for in 1 second or so affords decent productivity. With as fast as machines are today, that leaves a lot of latitude to conduct development which remains good cause in doing so, you may find yourself learning new tricks from others by way of freedom of expression! 🙂

Forgiveness and Tolerance: Great for People, Not so Much for Software

Despite being someone in technology I tend toward minimalism with technology because I, like many, believe that most technology doesn’t work and the pro-ported benefits technology typically isn’t worth the extra complications it brings.

Really consumers of software need to complain more to the authors when the programs/websites/apps don’t work or are buggy or are hard to use cause issues are all over the place. Instead, as I learned in grad school, users will typically blame themselves for not understanding how to use hard to use software. This behavior by users allows Software Engineers to be like weather folk: We can be way off, but we will be forgiven time and time and time again.

To the people of the Internet and beyond I say: It’s not just you. It’s the software too. Blame us. Help us, make us, help you. After all, without your input we have no idea what we’re supposed to be doing for you! 🙂

We Can’t Even Write for Loops Anymore???

In C# I like and use LINQ so the idea of using something to extend my abilities in iterating over enumerables is not foreign to me. And typically I do gravitate toward a foreach loop for some, basically, syntactic sugar that keeps me from having to use an indexer. I’ve also never in 12 years had a problem reading an indexer as part of something being iterated over a for loop. If I had to do something with say parallel arrays, I’d probably be inclined to use a for loop there vs. LINQ. Or if I needed finer control over the enumeration, such as say parsing command line arguments. In that case, my work history has made me someone who likes to not like to cede control to some helper and I’ve never had a problem reading an indexer. Or writing indexers where needed.

So in JavaScript, why did I find myself getting so opposed to changing a for loop to use a third party library? Something that behaves like LINQ, which I again, do use?

All I wanted to do was find the first instance of a key in an array to look up something in priority order in a hash. So I wrote what was basically:

for(var i = 0; i < keys.length; i++){
     if(source[keys[i]]) {
          return source[keys[i]];

return safeFallback;

I guess an alternative would have been something like:

var result = keys.findFirst(function(key) {
     source[key] !== undefined;

if(result) {
     return source[result];

return safeFallback;

Which is “better”? I guess the double ]] indexer in the first isn’t esthetically pleasing but is it wrong? More difficult to maintain than a function callback? I’m sure some would say so. But for they like me, their answer is their opinion.

As a contractor I do aim to yield to the opinions of those that work at my contract. I missed that today cause I didn’t identify a .findFirst style method before I ran out of time. :/ Kicker is one came through in a code review I looked at. That my answer was staring at me in the face just didn’t click. Had it, I’m sure I would have changed my code.

There is something about surrendering a basic thing like looping to a third party library as a rule that bugs me. Writing this I do think some of my hesitation is due to when I interview people, I like to ask LINQ questions cause if you don’t know what you’re doing with LINQ you can really easily write lousy performing software.

foreach(var item in collection) {
     var foo = usesItemAsIndexer.ElementAt(item);

I’ve seen something like the above in production code and performance has a bad time because of it. So, yeah, how does that findFirst method I called above work under the hood?

Given that a for loop is so basic and fundamental to programming, I think it being so should count for some ease of use and maintainability too. So in the end, because it was a big deal to my client I do wish I’d found a way to convert the loop. For me, I’ll never complain about such a thing and use a for loop in my own for me work whenever I like. 🙂