Searching More Effectively - Programmer Skills


Search is an important skill to programmers, it helps us to quickly find root cause, solutions, resource and etc.

Searching Code
Ctrl+alt+h to check call hierarchy
-- When write code, give class/methods easy-to-search name.
Senario 1 
One colleague asked me to help trouble shoot one problem, he wanted to split part of code from one project, so he copied all XX-related code to another project, but found that it doesn't work.

The error message is that it can't inject XXBean:
void doSomething(@Context XXClass xxBean)
Next I tried to find how old project works. The XXClass is not a spring component, so next I checked who called its constructors, then I found out that the constructor is called in XXClassProvider.

Now the root cause is clear: he forgot to copy the XXClassProvider.
@Component @Provider
public class XXClassProvider extends InjectableProvider<Context, XXClass> {}

-- Another way is to use "Open Type", search "* XXClass*" to find XXClass related class.

Github Search
Check the user guide and search the source code from project's github.
How to searching code in Github
Git - Tips and Tricks
in:path, in:file
path:sub-project/sub-folder
filename:the-name
extension:yml

From How to ignore pojo annotations while using Jackson ObjectMapper? I know in codehause.jackson, we can configure objectMapper to ignore pojo annotation like below:
objectMapper.configure(org.codehaus.jackson.map.SerializationConfig.Feature.USE_ANNOTATIONS, false);

But how to do in Jackson2(fastxml)? So I go to Jackson GitHub, then search USE_ANNOTATIONS:
https://github.com/search?q=org%3AFasterXML+USE_ANNOTATIONS&type=Code
Now it's easy to see that I should use MapperFeature.USE_ANNOTATIONS.

Or we can try Google search: site:grepcode.com USE_ANNOTATIONS
https://github.com/jersey/jersey/search?utf8=%E2%9C%93&q=DisableWADL

Eclipse Search
Avoid duplication
If you think the constant or function defined in your class maybe used in other classes, search the codebase first to avoid duplicate code.

Give classes and methods easy-to-search names.
Command+h          -> search
Command+shift+t -> open type
Command+shift+r -> open resource
Command+o         ->  list all methods of this class
Command+o+o     ->  list all methods of this class including inherited methods
F4 to show all sub classes, then scan related code.

Searching Log
During trouble shoot, it's common that there are 200 + lines in error log that is related: first we can try to use project package name, class name to quickly locate and scan in the error log; if can't, before try other approaches, make sure first quickly scan through all error messages. 
- In most case the root cause is just hidden in the log.
- Check More at: Error creating bean with name 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0'

Command history search
To run command that you have ran before.
history | grep git | grep erase
history | grep solr | grep cd
history | grep solr | grep start

Google search(do some search) first
Google search (do some search) first before attend meeting or join discussion or ask others for help.

Know/Use internal websites
Know company’s internal resource – where to find them
Know some experts (in company you) can ask help from

Labels

adsense (5) Algorithm (69) Algorithm Series (35) Android (7) ANT (6) bat (8) Big Data (7) Blogger (14) Bugs (6) Cache (5) Chrome (19) Code Example (29) Code Quality (7) Coding Skills (5) Database (7) Debug (16) Design (5) Dev Tips (63) Eclipse (32) Git (5) Google (33) Guava (7) How to (9) Http Client (8) IDE (7) Interview (88) J2EE (13) J2SE (49) Java (186) JavaScript (27) JSON (7) Learning code (9) Lesson Learned (6) Linux (26) Lucene-Solr (112) Mac (10) Maven (8) Network (9) Nutch2 (18) Performance (9) PowerShell (11) Problem Solving (11) Programmer Skills (6) regex (5) Scala (6) Security (9) Soft Skills (38) Spring (22) System Design (11) Testing (7) Text Mining (14) Tips (17) Tools (24) Troubleshooting (29) UIMA (9) Web Development (19) Windows (21) xml (5)