Life is too short: please, don’t waste your time writing code! I’m not saying that you don’t have to code, but many people tend to waste too much time typing on the keyboard instead of producing code. Mee too.
Following examples relate to Android’s world, but that can be easily adapted to other languages and programming tasks.
Aliases
Android developers, how many times do you have to call the command adb
? If your installation directory is something like
/opt/android/sdk
maybe you’re going to write /opt/android/sdk/platform-tools/adb
many many times a day.
Don’t do it! Instead add the android /opt/android/sdk/platform-tools/
directory to your path or create an alias so you will only need to write adb
!
I’ve also an alias for writing only logcat
instead of adb logcat
! ;-)
Some other alias examples:
Snippets and Templates
Every modern IDE has the support for snippets and templates.
Explore the built-in snippets and templates included in your IDE and use them as an example to write your own. You can create small blocks like a try/catch implementation or generate an entire class.
I’ve changed the default Android Studio template for try/catch block including exception logging. Go to File → Settings → File and Code Templates, select Catch Statement Body and change the default implementation with:
Log.d(TAG, "got exception", ${EXCEPTION});
If you use Robolectric you can change the default Junit4 Test Class implementation with the following, so annotations and basic imports are added automatically:
In Eclipse templates are under Preferences → Java → Code Style → Code Templates and Preferences → Java → Editor → Templates.
If you prefere Sublime Text you can find some useful Android Snippets in this repo: http://github.com/ribot/SublimeAndroidSnippets