开发者

How do I find methods?

Here's a somewhat general computer question. I've always been able to follow the LOGIC of programming, but when I go to code something, 开发者_如何学GoI always find that I don't know some method or another to get what I need to get done. When I see it, I always think, "OF COURSE!".

How do you go about finding relevant methods for your programming needs that are "built-in?" I don't enjoy re-inventing the wheel, but I find it difficult to find what I need to do what I want to do.


First try Google:

You can use google to search your required method. For example If I want to search a value in array in PHP then I go to Google and type "Search values in array in PHP". I find my required function at first place.

Then try Standard Documentation:

Try standard documentation to search for your required method. For example if my problem is related to strings in PHP then I go to String Functions documentation and find the required function.

Finally try Stackoverflow:

Otherwise you can ask your problem at Stackoverflow for your required methods and libraries. You will always get a shortest way.


What you are asking here is for the best way to do research. Well, that's hard skill to explain, even more so to teach.

Nevertheless here are some tips:

  1. Go to a search engine. It makes no sense to start in a place like MSDN, since all of its content is indexed by the search engines anyway. Phrase your question several different ways.
  2. As you learn more about the issue you will learn new vocabulary about it. Use that new vocabulary to do even more searches.
  3. If the searches turn out empty, switch to browsing a specific section of the official documentation that you think is the most related to what you are doing. If nothing else, it will expand your horizons around the issue and give you more vocabulary to do more searches.
  4. Finally, if all else fails ask a question on StackOverflow explaining what you want to do as clearly as possible.

Note that if there's a simple API that does what you need, you will rarely reach step 4.


You say:

It's very frustrating to suddenly find an "easy" button mid-way through.

Try to see it differently. Think of these moments as blessings. You've just learned something. You invested a lot of effort - and instead of seeing that effort as wasted, see it as critical to proper learning. You - better than the guy who just happened across the magic method - really understand what it's for and something about how it works. And you really, really, understand why you need it, and you properly appreciate its value. You're never going to forget that method.

So it was costly, but you learned something important. Celebrate, and move on.


It is usually included in some form of documentation. Most IDEs support the documentation format and gives you auto-complete functionality.


if you are using MVS so MSDN is really good for it


In addition to this and this answer above, google's basic and advanced searching tips prove very helpful.

In addition to above, changing the order of keywords in search criteria also sorts the list in different orders.

In essence I believe that searching is still an art rather than a science, and is best learnt - quoting from David Reis' answer above: "2. As you learn more about the issue you will learn new vocabulary about it. Use that new vocabulary to do even more searches."


Search in the API documentation. But the best way to (I found so) is to search on the internet for multiple solutions and then choose the one that you think is best. Make your search as narrow as possible. For example you want to implement random number generation function, then search like this, "How to generate random numbers in Java?".


Namespaces, namingconventions, Autocomplete/Intellisence

I assume that you are trying to find some kind of Object-Oriented-apis . I use .net in my example.

First try to find a class that might be responsable for the method you are looking for.

Example: If you want to "Make a new Directory in the Filesystem" you must know (or learn) that (in dotnet) these classes are in the namespace System.IO:

This namespace contains subnamespaces like Compresseion and Classes like File, Path, Directory, ...

Second you sould know NamingConventions. There are common Naming-Prefixes for methods like Get, Set, Insert, Create. In the documentation for class Directory you will find a CreateDirectory-Method.

If you have an intelligent editor that knows your programming language and the classes and namespaces learning is much easier. In the dotnet-world this feature is called Autocomplete/Intellisence

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜