Reflections on Coding Standards

strongly-typed-300x210Last night I had drinks with my friend. His wife is pregnant and I wanted to celebrate the good news over a few beers.

We talked about the unknowns of impending fatherhood. And the conversation quickly transitioned to fitness and staying in shape.

My friend is hardcore. He runs multiple marathons a year.

He’s found his drug and he wants to share it with me. I’ve been resistant for a long time. But I started working out. I like swimming. The solitude is bliss.

I thought he’d be happy to hear that I’d taken up an exercise that I enjoyed. Turns out, working out 3 times a week is not enough. He said, “Dave, exercising is great and all but you need to be training toward something.”

The best way to keep your workout steady is to commit to a big event in the future.

“You gotta have a goal. Because everyone gets sick. But when you sign up for an event, a challenge, a marathon you either show up and compete or you get a DNF.”

The dreaded DNF.

“Your friends will say, what happened? They’ll shame you publicly for committing and not coming through on your promise. They’ll say, ‘What happened? Did you get injured?'”

I stopped him mid-sentence and said, “Have you heard of Athletic Software engineering? I never want to get a DNF.”

Coding standards

Coding standards promote readability. Coding standards are the rules that programmers agree to so their code can be shared and understood quicker and easier. Coding standards exist to enforce style consistency.

IntelliJ automates style consistency

IntelliJ IDEA does everything. “It slices, it dices, it splices your multimedia!”

Not only does IntelliJ support configuration management, it formats your code for you.

My favorite add-on for Firefox is called DownloadThemAll! It’s a add-on that allows users to use the computer’s regular expressions to parse a web page and download the content they want from the site their on. IntelliJ automates tedious behaviors like DownloadThemAll automates downloads.

Strongly typed Java will save you

Java has a lot of interdependencies. I used to think that was a bad thing. Not only does strong typing prevent me from mixing up my datatypes and calling the wrong methods on the wrong class, strong typing gives the IDE the ability to run checks on my code automatically.

Because of strong typing my IDE knows when I am running potentially risky code and prompts me to surround the code in a try/catch block and it gives me to exceptions that the code could potentially run into.

Java has strict typing allows for features like CheckStyle to go through my code and base things off of types. This way I can not only ensure that I won’t run into any errors at compile time, it also saves my code from exceptions that may be thrown by code that does not maintain its state so well.

The ability for the Java compiler to check all of the options that might be thrown is a godsend. Static typing allows me to write code that can have try / catch methods. This saves me at runtime. A Java method that may preform some behavior  that I do not want can be prevented because Java has me covered. This array accessor may be out of bounds. No worries. I have an ArrayIndexOutOfBoundsException.

Reflections on WODs finished

This week I forked a repository, ran it through CheckStyle and pushed it to GitHub.

This first run through took over 18 minutes.

I am still getting stuck on the menuing system in IntelliJ IDEA. I came up with a list of lingering questions and lessons learned from this experience.

Lingering Questions:

  • What does “can be package local” mean?
  • Using ctrl+space to find the package with this feature is great.
  • I am not certain what I am meant to write after a @param or a @return.
  • What is the keyboard shortcut to run “Inspect Code?”
  • How do you know it wants an @Override annotation?
  • What is the keyboard shortcut to remove a whole line?
  • How do I save my master password to github inside of IntelliJ. I don’t want to have to put it in every single time.

Lessons learned:

  • Cmd + /  to remove the one line comments.
  • Code > Optimize Imports to convert wildcard imports into fully qualified import statements.
  • I want to learn how to select code and have it get surrounded with multi-line comment tags.
  • Shift + F6 allows me to refactor and rename variables.
  • Start doing a new Java Doc comment and it will fill out all of the @params and @returns for you.

Reflections on WODs done multiple times

I managed to shave 6 minutes off of my initial time.

I am learning that I can import projects directly into IntelliJ IDEA from the project panel that shows when IntelliJ starts up. I also used some of the keyboard shortcuts this time. I believe I saved some significant time by using the Refactor>Rename shortcut Shift+F6.

I also saved significant time letting IntelliJ create my Java Docs for me. Instead of trying to update the existing Java Docs, I created a new set right above the method and IntelliJ did it for me.

Major lesson learned

Don’t fight the IDE. Dance with it.

This slideshow requires JavaScript.

Author: David Neely

Professional Software Developer. Technology and Web Coordinator at the University of Hawaii's Manoa Career Center.