Featured Post

The great debacle of healthcare.gov

This is the first time in history when the president of the United States of America, or probably for any head of state around the world,...

Tuesday, November 13, 2007

Best practices in software development

These are the compiled list of practices that I believe really help a software engineer to be efficient as well as optimally utilizing the skills and resources.

1. Write the initial plan at the beginning of the day. At the end of the day, update the status of your planned activities. It helps to:
  • Assess how effective and efficient you are.
  • Reduce the number of items (sometimes insignificant) forgotten.  [Planning]
2. Give preference to written communication instead of verbal communication. [Collaboration]

3. Keep a notebook with you. Write what you think, what you listen or what you are asked to do. [Planning]

4. Visually represent your idea. Use UML to represent your idea. This would help you to identify shortcoming of your solution and also increase your image to the team members. [Design]

5. While implementing/coding a logic, never derive the business logic from data. Even though it may look like that the change in the data is very unlikely and also controlled through your code, don't assume that it'll remain such down the line. Always use the true business indicators such as "flag", "state", "category" etc. to write your business logic. Some of the dead wrong software logic are: to identify a user as a Sales user, checking the value of  the "commission" attribute; if an employee has direct reporting employees to determine if that employee is a manager. Rather, use appropriate flag or indicator if the person is a sales person or a manager. [Coding]

6. Always document your assumptions. Never assume that people will remember your assumptions; you may yourself forget your assumptions in few weeks, if not months. [Planning]

7. When you're asked to provide a ball park figure for the effort of implementing a feature, try to provide a range of effort estimation rather a concrete number; and if you can afford, mention the assumptions that you've made to estimate the effort. [Planning]

9. Never trust that user will provide data to the application in the case (upper case or lower case) you expect. This is specially true when you use the data to compare against a database table or against string literals in the code. The bottom line is to compare in case insensitive manner.
e.g. to check a user while logs in if the user exists, compares the user id in case insensitive manner or convert into upper case on both side of the expression. It will save you days in debugging production issues. [Coding]

10. Testing of software has to be verifiable. This can be identified summarize into the simple statement: Test result should be verifiable. The soul purpose of this principle is to make sure that every steps of testing in the software are verifiable which would have profound impact on the quality of testing. This would alleviate the controversy of "this was working before" symptom. [Testing]

11. Prefer database over file to keep the application configuration. It's always easier to access and modify the database than a file within the deployed application. Some example of benefits of using database are: easy to query, easy to create report, usually doesn't need application downtime (unless designed badly), corporate production environment is less stringent to database change than application file change, etc. [Design, Coding]

12. Never hardcode the deployment infrastructure in the application. You never know what would be the next deployment infrastructure your application would get. Also, never use IP address, physical server name, database server name, etc. in your application. Always use virtual names that could be mapped to that physical environment [Design]

Wednesday, November 7, 2007

Useful vi commands

Useful vi Commands

0. :q -> quit ; :w -> write the change ; :q! -> quite anyway without saving ; :qw -> quite after saving the changes

1. yw -> yank (copy) a word
2. yy -> copy the current line
3. yG -> copy from cursor to EOF
4. 2y -> copy 2 lines from cursor
5. y2w -> copy 2 words from cursor
6. p/P -> copy before or after cursor

7. :set number -> see the line numbers
:set nonumber -> hide the line numbers
8. :set list -> show the newline character
:set nolist -> hide the newline character

9. :%s/search-text/replace-text/g -> Search and replace text with greedy option set
10. /search-text -> search any text and then press n to search next or ? to search previous

11. Ctrl+f -> to move one screen forward
12. Ctrl+b -> to move one screen backward

13. :line_number -> to go to the specified line number

14. * (Shift+8) -> Hightlight the word at the cursor position and search for next match
:noh to remove the highlight
15. :e -> Open another file to edit

16. :J -> Join the line with next line giving a space in between

17. : %s/^I/\r/g -> Replace all with ; works on gVim
: %s/
^I/^M/g -> to achieve the same in unix vi. To get '^M', use Ctrl+v first then hit enter.
: %s/\m/,/g -> insert ',' between each character. Works on gVim
: %s/\n/,\r/g -> replace the new line (\n) using ',' and carriage return (\r) . works on gVim
: %s/.*ABCD/ABCD/g -> replace words from beginning of line up to word 'ABCD' and replace that with only word 'ABCD'
e.g. "10/17/2008 11:55 AM 229,888 ABCD XY - FOO - 1.0"
becomes "ABCD XY - FOO - 1.0"
:'<, '>s/^^I/&A/g -> replace all tabs from beginning of the line with A (the selected lines only)
:%s/^^I/&A/g -> Same as above without any selection
:%s/\s*$// -> replace all trailing white spaces

18. vEU -> change from the cursor to end of word to uppercase
v$U -> change from the cursor to end of line to uppercase
vEu -> change from the cursor to end of word to lowercase
v$u -> change from the cursor to end of line to lowercase

19. u -> undo delete
U -> undo the last change
Ctrl+r -> Redo the last change

20. : -> to recall history

21.: & -> repeat last :s command
: . -> repeat last text changing command
: , -> repeat last search command. In gVim use 'n'


22.
M -> Move to the middle of the current screen
H -> Move to the top of the current screen
0 -> Beginning of current line
+/Return -> First character of next line
dL -> Delete up to last line on the screen
D -> Delete remainder of the current line
"xyy -> copy current line to buffer x
"xp -> copy the line from buffer x

23. Vertical selection and insertion
^v to start vertical selection
press 'I' or 'i' then enter any letter you want to append and finally press escape.

24. Delete lines with search result
g/string/d - Delete lines that contains the 'string'
v/string/d - Delete lines that DOESN'T contain the 'string'

25. Sort a file
:sort

26. Counting words
:%s/pattern//gn - Count the pattern
:%s/[^ ]\+//gn - Count the space delimited words

27. Recording
Hit q and register character (alphanumeric) e.g. x
Hit q again to stop recording
@x to rerun the recorded keystroke recorded

28. Find next key word
i (insert mode) -> Ctrl -> i
this would show the keywords as drop down values to be picked for


Resources:

http://www.brezeale.com/technical_notes/vim_notes.shtml
http://www.rayninfo.co.uk/vimtips.html
https://xyz.pp.se/~thnov/vi.html
http://www.lagmonster.org/docs/vi2.html
http://www.unix-manuals.com/refs/vi-ref/vi-ref.htm
http://vim.wikia.com/wiki/Vim_Tips_Wiki - Vim tips wiki

Tuesday, November 6, 2007

The simplest way to create an executable jar in java

The simplest way to create an executable jar in java.

1. Create the MANIFEST.MF file. Add the Main-Class in the manifest file:
Main-Class: Main

2. Create the jar file
jar cvfm factor.jar MANIFEST.MF *.class com gnu

3. Execute the Main class from the executable jar
java -Xms512m -Xmx512m factor.jar

Note: The Class-Path: entry doesn't work, at least in jdk 1.4 as expected i.e. it doesn't load the jar file into the classpath. The Class-Path only inform the java command to search the libraries in the relative location from the current directory. So if the jar files can be found in the location mentioned in the Class-Path: entry, then it works