Close

Versioning NPM Packages in TFS

So I recently needed to build an NPM package with TFS, and wanted the version number to be updated automatically on build. But after searching, I couldn’t find a good example of how to do it, and TFS seemed to have no tools built in to help.

So I finally I just wrote a simple Powershell script to handle it, and wanted to reproduce it here for the benefit of others who have the same issue:

cd $env:BUILD_SOURCESDIRECTORY
$a = Get-Content 'package.json' -raw | ConvertFrom-Json
$a.version=$a.version.Substring(0, $a.version.LastIndexOf(\".\")) + \".\" + $env:BUILD_BUILDID
$a | ConvertTo-Json  | set-content 'package.json'

Or, if you use GitVersion like we do, after running the GitVersion build step, you will have new environment variables with version numbers in different formats available, which can be used like so:

cd $env:BUILD_SOURCESDIRECTORY
$a = Get-Content 'package.json' -raw | ConvertFrom-Json
$a.version = $env:GITVERSION_NuGetVersion
$a | ConvertTo-Json  | set-content 'package.json'

Hope this helps anyone trying to build and publish NPM packages as part of a TFS build!

Commonly Misused Programming Terms

One big challenge I often see new programmers struggle with early in their careers is that they often don’t know the correct vocabulary to describe the things they deal with in code.  As a result, often times a lot gets lost in communication when they misuse words while talking to senior programmers, because they are effectively describing something different from what they mean.

A few years into my career, I noticed that I was using certain words interchangeably when describing things without really understanding the difference between them. So I started trying to research each term I felt I didn’t fully understand and get into the habit of using it correctly as much as possible.

As I began to learn the difference between various terms, I realized something: the senior programmers on my team always used terminology correctly, while junior programmers did not. Furthermore, the junior programmers were often inadvertently describing things that were either nonsensical or simply wrong by accidentally using the wrong words to describe the code constructs they saw. While it is often possible for people to infer your intention from the context of what you’re describing, it is worth making an effort to use the most correct terminology possible so that you can avoid the possibility miscommunication with your fellow programmers.

This blog will be a quick overview of a few terms which I commonly hear misused or misunderstood by junior programmers, in the hopes of helping people communicate themselves more effectively to their coworkers! The terms will mostly be ones relevant to modern Object-Oriented Programming, and I’ll include code examples in C#, but I think that you will find that there is a lot of cross-over between various languages.

Field versus Property:

The following code example defines one Field and two Properties:

devenv_2016-02-22_21-01-01

Fields are local values defined on a class which, when on the left-hand side of an assignment statement, do not execute any logic, as they have no concept of a getter or setter. Properties, on the other hand, execute some logic during assignment statements that you can either leave with default values by using auto-properties, as in the property named AutoProperty, or can have custom logic defined for their getters and setters, as in the example named CustomProperty.

One important difference to note: since interfaces can only include methods, interfaces cannot expose Fields. They can, however, expose the getters and setters of Properties.

Class versus Object:

devenv_2016-02-22_21-07-25

The two small code snippets in this screenshot demonstrate the difference between a Class and an Object. Classes are definitions of a data structure which expose a constructor we can invoke in order to create instances of that data structure. An Object is a single instance of a Class. To put it another way: Objects have a point in your code where they are created, then exist until they are eventually cleaned up by the garbage collector when they are no longer referenced. Classes exist at all times after compilation, and are used to create Object instances.

Interface versus Implementation versus Inheritance

devenv_2016-02-22_21-14-44

Here we see examples of Inheritance, an Interface, and the Interface’s Implementation. An Interface is simply a definition of a collection of methods made publicly available by any class that Implements the Interface. Our Interface declares a single public method named Subtract which takes two integer arguments. But you will notice that IInterface does not define any method body for this method. The method body must instead be defined by any class that chooses to Implement that interface.

If we look at our class named Implementation, we can see that it Inherits from our class named ParentClass, and Implements our Interface named IInterface. The method body of the Subtract method defined in IInterface is actually declared within our Implementation class. If we did not declare public methods that matched all the methods defined in the Interface that our class Implements, this would result in a compiler error.

Notice also that Implementation does does not define a method body for Add. That is instead done in our class named ParentClass. Parent class both definesand implements the Add method. As a result, our Implementation class will Inherit this method definition from its ancestor class. If we were to invoke the Add method on an instance of Implementation, the code which would execute at runtime would actually be the code declared inside the method body of ParentClass.

Note also that in C# (and any language which does not support multiple Inheritance) – a class can only Inherit from a single class. Conversely, a single class can Implement as many Interfaces as you wish.

Operator versus Operand

devenv_2016-02-22_21-27-28

Operators are symbols (or collections of symbols) in code which perform some operation on the values immediately adjacent to them. The values which are operated on in this way are called Operands. C# has Operators which take one, two, or three Operands. They are called Unary Operators, Binary Operators, and Ternary Operators, respectively.

In the screenshot above, I have highlighted each Operator in green, and each Operand in red. (Note: the equals sign ‘=’ is the assignment Operator, but I did not highlight it since it won’t be discussed directly here.)

Beginning at the top, we have the binary Addition Operator ‘+’ which accepts two numerical Operands and returns their sum.

Next we have the unary Logical Not Operator ‘!’ which accepts a single boolean Operand and returns the inverse of its value.

And last we have the Ternary Operator ‘?:’ – to which we are passing the result of a Logical Equality Operator whose Operands are the variable ‘a’ and the integer constant ‘5’. Depending whether this value is true or false, determines whether the Ternary Operator returns its second or third operand respectively. If ‘a’ is equal to 5 when this statement executes, then 0 will be returned, otherwise 1 will be returned.

Line versus Statement versus Expression

devenv_2016-02-22_21-42-29

An Expression is a sequence of Operands and Operators which evaluates to a single value. In the example above, ‘5 + 4’ and all of the other arithmetic operations we perform are Expressions.

Lines refer to a single line of code, which may contain one or more Statements and Expressions.

Statements refer to many actions your program might execute. As you step through your code using a debugger, you will sometimes find that individual Lines of Code may be hit multiple times by the debugger. This is because the C# Debugger breaks on individual Statements, rather than individual Lines.

In our example above, the first two lines each contain a single Statement: an integer variable declaration statement, and an assignment statement which stores the result of the Expression 5 + 4 into that variable.

The third line, however, contains 3 variable declaration Statements, 3 assignment Statements, and 3 arithmetic expressions.

Functions versus Methods

For this example I will use Javascript, since C# does not have a way to define Functions which are not also Methods:

devenv_2016-02-22_21-55-33

Functions are definitions of a collection of Statements which may be executed at runtime.

Methods are specific examples of Functions whose context for execution is an instance of an object. This means that those methods will have access to a particular object’s private data, which may not otherwise be accessible. Most languages including Javascript and C# use the ‘this’ keyword to as a reference to the object instance to which a Method belongs at runtime.

In our example above, Add would commonly be described as a Function, while Subtract could be considered a Method, since it depends on being executed within the context of a particular object, whose properties it will access with the ‘this’ keyword.

Parameters versus Arguments

devenv_2016-02-22_22-02-16

Parameters and Arguments are closely related and often confused (in fact I only just recently learned the difference thanks to this StackOverflow post)

Parameters are the names in a method declaration which refer to values which can be passed to a method at runtime when it is invoked.

Arguments are the values passed in to fulfill a method’s Parameter values when it is actually invoked. I have indicated the Arguments in the screenshot above in red, while the Parameters are indicated with green.

 


Hopefully, this blog will have helped you learn to better distinguish between some common programming terms, as well as identify the specific code artifacts to which they refer.

If you found this useful, let me know in the comments and I may do another blog about programming terminology. Let me know what terms you feel the least comfortable with or see other programmers confuse most often and I’ll discuss them in a future blog post!

Fix for Logitech G930 Shutting Off Every 15 minutes

Not too long ago I shopped around for a wireless headset which had surround surround support, and eventually settled on the Logitech G930 Headset.

While the hardware is excellent, and the sound is quite good, sadly the software designed to support the surround sound, macro keys, and showing the battery status is the Logitech’s Gaming Software suite, aka LGS. I have never used this software with any of their other products, so I can’t comment on its overall quality, but its support for the G930 headset is really quite awful.

Google’s search results are littered with people complaining about various issues with the headset’s drivers and the gaming software, some of which are quite severe. Logitech also doesn’t seem very interested in solving any of the driver/software problems for this headset, as some of the simpler issues have been open on their support forums for 5+ years without a patch being released.

It’s really a shame because the hardware itself is quite good, and it is the only headset I’ve managed to find which is: wireless, supports surround sound, and also has macro keys on the headset (useful for push-to-talk and skipping songs while I’m in the other room.)

One particularly annoying problem many people seem to have is that, while the headset works just fine out of the box, as soon as they install the Logitech Gaming Software, it begins to turn itself off every 15 minutes! This happened to me as well, and it turns out that it is just a default power-saving setting in the XML config used by LGS to determine how it should manage the headset. Since it’s a config file you’d think that you could just change the headset’s settings in LGS – no such luck. LGS provides no way in the UI to update this setting, requiring you to find and modify the XML file manually, or just get used to it shutting off every 15 minutes.

With the default install location, the file is located at the following path: C:\Program Files\Logitech Gaming Software\Resources\G930\Manifest\Device_Manifest.xml

You can simply change the value in the <battery> node’s turnOffInterval attribute to “0” to disable this battery saving feature entirely.

This is well and good, but I always forget the path when I reinstall the software on a new machine, and don’t feel that this is very intuitive for people who aren’t comfortable editing XML config files manually.

So tonight I wrote a simple Windows application to help users modify the battery configuration settings which are not normally editable through LGS and uploaded it to Github.

If you are experiencing this issue with your G930, I hope either this blog or my application helps. And if you are a programmer who wants to make an improvement and submit a pull request, feel free to do so!

Announcing Decide Among Friends!

Hey, guys!

I wanted to invite everyone to try out a new website I’ve been working on: http://decideamongfriends.com/

My coworkers always had a hard time figuring out a fair way to decide on a lunch location for 6+ people each day.  So I thought to myself someone should make a tool to help with this!

So then I did.

For opinion-based decisions between many people, I consider it to be superior to other voting websites such as http://strawpoll.me/ because it allows you to demonstrate a varying level of preference between every option by dragging the sliders between -5 and +5.

It’s been really successful among my fellow lunchgoers in the office, and I hope that other people out there find it useful as well!

Starting the Hello Language Project

So I recently realized that while I often read blogs and social media comments about a really wide variety of languages, I actually only tend to use a handful on actual projects I work on. I’m most comfortable with C# and Type/Javascript, so those are the tools I use to solve programming problems I encounter. I have about 5 years of experience in both, and between the two, I can write code for basically every platform thanks to projects like mono and the ubiquity of Javascript. They’re really versatile languages.

That’s all fine and well, but I want to break out of my comfort zone a bit and actually write code in all of these languages I frequently hear about. At first I thought that coming up with a project for every language I was interested in would be prohibitive, and if I’ve never used them before, how would I even know what a good project for a language might be?

So to break out of my analysis paralysis, I decided to start the HelloLanguageproject as an exercise for myself: to write Hello World, Fibonacci, FizzBuzz, and possibly a few other very simple applications in every language that interests me. So far I’ve done 17 languages, including Rust, Scala, LISP, and Fortran, and plan to do about a dozen others including D, Go, and Swift.

It’s actually been a really interesting exercise just switching between multiple different syntaxes for solving problems in a single evening. If you have any suggestions for cool languages I should take a look at, a favorite feature of a language I should explore, or small exercises I could do in multiple languages to highlight their differences, please let me know in the comments!

Why the Open Code of Conduct Isn’t for Me

Github recently announced that they are adopting a new code of conduct for their open source projects. Specifically, it is the Open Code of Conduct, published by the TODO Group.

This inspired some debate on Reddit when it was posted, and I groaned inwardly when I saw it: ugh, more political correctness.

Yet this was clearly a well-intentioned and well thought out effort on the part of Github, so I asked myself: why does it bother me so much? Before I elaborate, let me cite a few snippets from the Open Code of Conduct:

Although this list cannot be exhaustive, we explicitly honor diversity in age, gender, […] and technical ability*. We will not tolerate discrimination based on any of the protected characteristics above[…]

Harassment and other exclusionary behavior aren’t acceptable. This includes, but is not limited to:

  • Discriminatory jokes and language*.

If someone has been harmed or offended*, it is our responsibility to listen carefully and respectfully, and do our best to right the wrong.

(* = emphasis mine)

While I agree with most of the Open Code of Conduct (as well as its underlying intent) – these passages struck me as being problematic. They, like all forms of political correctness, center around people being offended, sometimes about things like technical ability which can and should be spoken about frankly in any open source project.

Here is the problem with using offensiveness as a standard in a code of conduct:

  • It judges the speaker by the listener’s opinions.
  • Opinions are subjective and cannot be known by the speaker until after they speak.

Judging and punishing the behavior of those who speak based on the sensibilities of those who listen is a standard which is inherently unfair to the speaker. This precipitates an environment where the exchange of ideas between people who differ is impossible if either of them thinks that the other may find the topic offensive. This carries with it the danger of stifling communication and learning between people who would otherwise benefit from a conversation that might just ruffle some feathers.

Being offended is a choice

I am a Christian. When people speak ill of religion in general, and of Christianity in particular, I have a choice about whether to be offended, even when confronted with very vitriolic assaults on my core beliefs.

I choose not to.

The reasons for this are simple: I respect the cognitive abilities that other educated human beings put to use in forming their opinions about the world, and am eager to hear about the conclusions that they have drawn. I value the opportunity to exchange ideals with others and have had my life and my thoughts enriched by such exchanges in the past.

I have a lot of respect for both Richard Dawkins and Christopher Hitchens, even though our opinions on religion differ drastically. I would consider it both rude and oppressive to try to create a world in which people who disagree with me are afraid or unable to speak their minds.

Just because one person was offended does not mean that another person attacked them

Many of the things people choose to be offended about are the same things that other people honestly and unironically believe. The mere act of voicing one’s own opinion on a topic such as religion or politics can be interpreted by a sensitive listener as an offensive attack on their beliefs. The listener’s perception does not equal the speaker’s intent. Conflating the two mindsets like this can lead to one person’s opinions being punished due to other people’s indignation.

Opinions are subjective

Because opinions are subjective, it is very easy for people who wish to abuse these sorts of systems to choose to be offended by things they don’t like in order to demand punishment for those who disagree with them. In extreme examples, they may even take offense at someone else’s treatment of them, while simultaneously treating others in the same way.

Systems that punish offensiveness open themselves up to exploitation by such people.

Not all speech can be judged the in the same way

While it is true that sometimes people thoughtfully voice their honest opinions, people also tell jokes, speak flippantly, say things without explaining their reasoning, and employ language techniques such as idioms, metaphors, irony, sarcasm, and hyperbole. Given the inherent complexity and ambiguity of human speech, combined with the fact that any two people’s grasp of a language must necessarily differ, there is no guarantee that the offended listener has correctly inferred the speaker’s intent.

Intent is a better metric of behavior

It is not uncommon in criminal cases of harassment or slander for prosecutors to be expected to show not only that the defendant said or did the things in question, but that they did so with the intent or knowledge that it would hurt the victim. We can easily use the same system in a code of conduct, to weed out the same sort of negative behavior without resorting to judging one person’s words by other people’s thoughts.

In Summary

This post may sound pedantic, but I think that the difference between intent to offend and being offended is an important distinction. When an educated computer scientist makes a flippant claim that “Haskell is useless,” I think that their own (in this case jokingly positive) intent when saying it should determine whether punitive action is taken against them, rather than the fact that a Haskell fan felt offended by it.

I hope that Github will reconsider their decision to use subjective metrics like this as a part of their code of conduct. I hope that they will let the people who may say things I disagree with continue to speak their minds honestly. And when they do, I hope Github judges their actions based on their own mindset and not mine.

This is the internet, and I’m here to learn about other people’s thoughts, not be protected from them.

 

EDIT:

I acknowledge that Github chose this Code of Conduct in an effort to improve their community. I also think that it will actually do that, and applaud their effort. I do not think that the political correctness spies have scored some great victory today, nor that the sky is falling.

But I see an edge-case that could result in abuse and misunderstanding. I also believe that a Code of Conduct, like other code developers write, can benefit from constructive criticism. I think that code must be made durable to stand up over time, and I think the best code results from collaboration and many small improvements from people with different perspectives. This is mine.

Consider it a meta-pull request. 🙂

The annoying MySQL Web Platform Installer Bug

So I recently ran into the following error while installing the second WordPress site on a fresh VM:

The specified password for user account 'root' is not valid, or failed to connect to the database server.

MySQLError

After following a few guides and going through the steps to reset the root password on my MySQL installation and continuing to get the same error, I finally stumbled across the solution in this blog post.

Since this issue sucked up quite a bit of my time, I figured I’d mirror it on my blog as well. I didn’t need to edit the registry key, simply installing the MySQL .NET Connector was enough to fix my issue:

MySQLFix

Not quite sure why this is needed, but it worked for me. Hope this helps someone else out there!

Back to top