Tag Archives: Java

go lang gopher

Working with Go lang

During my internship at IBM Singapore, I am using go lang to develop the back-end of the software. It is a nice new language, with a lot of features that I found really useful. Previously I have mostly used Java and JavaScript in programming, and go lang has the best of both.

First-Class Functions

I have always liked the flexibility with functions in JavaScript, the fact that you can treat functions like any other normal objects and pass them around. This advantage made me hate Java where methods are just methods.

In go lang, functions are surprising quite flexible, they can be used as values and passed around, and anonymous functions with closure are supported. All of these are still on top of statically-typed nature of the language.

Multiple Named return values

This is a great feature in my opinion. For Java and JavaScript, functions can only return one value, causing a lot of troubles when you want to do error checking or simply need to return multiple values. In go lang, the ability to return multiple values makes all of these very easy. On top of that, the return values can be named as variables in the function signature and saves the trouble of declaring them in the function’s body.

And more

Go lang also has great packaging system, allowing reusable components to be packaged and easily integrated into other projects. It has OOP-styled types like struct and interface. It also supports encoding and decoding of JSON internally.

I have not had a chance to use the multi-threading and concurrency components of the language, and I shall wait to be delighted.

Tip and tricks on using the eclipse

I have learnt from CS2020 a few useful tricks to make my life easier and an enjoyable one when using the eclipse.

This is a feature, not a tip, but I really like the automatic indentations in eclipse. When copying and pasting codes, they are automatically indented in the context, saving the trouble of indenting them manually.

Here are some useful short-cuts and tips I learnt so far.  This list may be expanded in the future.

Multiple edits (of the same variable name)

Alt + Shift + R

Very useful for changing the name of variable halfway


Crtl + Space

This is like tab in linux and sublime text. eg. sysout in java will be auto-completed as System.out.println();

Auto format

Ctrl + Shift + F

Automatically add or delete extra spacings to make code neat and clear, also fixes the over-lengthy lines

Auto fix import

Ctrl + Shift + O

Automatically add the necessary imports and delete unnecessary imports for the class

Auto-add getters and setters

Source – Generate Getters and Setters

This automatically add these two classic methods to the class body

Extract method

Select the code and right click and choose Refactor, extract method

This helps to break down a long method to several sub-methods to make the code more organized, also helps to maintain layers of abstraction by establishing hierarchy in methods.

Using Java Naming Conventions and Andriod Naming Issue

This article on naming conventions is based on Java, some rules apply to other programming languages as well.

I highly recommend this article to new programmers who are yet to have their own naming styles (for functions, variables, etc).

This is especially useful if you are just starting to learn programming.

If you are a experienced programmer with your own naming styles, you may want read this and see if there is anything to improve your naming techniques.

Original article: http://java.about.com/od/javasyntax/a/nameconventions.htm

Note on meaningfulness and length:

When choosing a name for an identifier make sure it’s meaningful.

Don’t worry about the length of the name. A longer name that sums up the identifier perfectly is preferable to a shorter name that might be quick to type but ambiguous.

There are 4 types of letter cases for naming:

Lowercase is where all the letters in a word are written without any capitalization e.g.

Uppercase is where all the letters in a word are written in capitals. When there are more than two words in the name use underscores to separate them e.g.

CamelCase (also known as Upper CamelCase) is where each new word begins with a capital letter e.g.

Mixed case (also known as Lower CamelCase) is the same as CamelCase except the first letter of the name is in lowercase e.g.


Standard Java Naming Conventions:

Basically, follow the naming guidelines below when you write your programs, you will find your programming process more systematic, efficient and professional than if you don’t.

Packages: Names should be in lowercase. With small projects that only have a few packages it’s okay to just give them simple (but meaningful!) names:

Continue reading