How do I understand Libraries?

Ok, noob question:

When I download a library, sometimes there's a thorough explanation of all the included instances an functions related to it in the ReadMe- file. Then again, most of the time there's not.

If there is, all is fine and I can read and try my way forward to the best of my ability. But when there's not, I can't even begin to understand how I'm suppose to use the library. Through some telepathic contact with the creator? How is it even possible to know which functions to call and what keywords I have accessible?

I'm hoping there's a trick to decode those libraries that you, the vastly more experienced coders, can teach me. There are so many of them that seems perfect for me, but ends up completely useless. It seems strange that someone would upload a library without giving people the key to use it.

How is it even possible to know which functions to call and what keywords I have accessible?

Have you tried looking at the .h and .cpp files of the libraries ?

Almost every library has example(s). If you add a library (using the Library Manager in the Arduino IDE) or with a *.ZIP file (also with the Arduino IDE), then the menu of the Arduino IDE will have the examples of that library.

With many libraries I have to read the *.h file, to see which functions are available. And I read the *.cpp file as well to see what they do.

Often the usage of functions is described in the library's code files (.c, .cpp, .h ...). If not, maybe the code is easy enough to read and functions have meaningful names and parameters so that they don't need explanations.

But if a library doesn't use meaningful names, no explanation, no examples, and code is hard to read, then I usually delete it and find an alternative...

Mixe:
But when there's not, I can't even begin to understand how I'm suppose to use the library. Through some telepathic contact with the creator?

Alas, inadequate or non-existent documentation seems to be the hall-mark of Open Source software. People who are interested in writing programs seem to have little interest in writing documentation. The commercial software producers pay people to write documentation.

Personally I don't consider a few examples to be adequate documentation.

Perhaps it is true that "you get what you pay for".

I have also had the experience, and not just with Arduinos, that it was easier to write my own program than it would have been to figure out why a library was not doing what I thought it should.

...R

Yes, I tried reading the .cpp and .h files, but if you're not capable of actually writing your own libraries, those are most often not understandable.

It's sad, but I lean towards thinking that Robin2 is right. Naturally, in my frustration, I angrily concluded that all coders are elitistic aspergian idiots that don't care if anyone besides their closest friends and idols understand what they do- but then why upload your stuff to a public platform? So that can't be the whole truth.

Overall, there's a lot of tutorials for the absolute beginners, but when you've passed the "this is how you install a library"- stage, there's a HUGE gap of pedagogical information until you're semi-pro. It's like beeing told the way by this old lady who lived in the neighbourhood all her life. After the first detailed part there's suddenly big jumps in consistency and skipping of necessary details.

Gratefully accepting tips on where to find tutorials off intermediate difficulty.

Which library ?

Mixe:
but when you've passed the "this is how you install a library"- stage, there's a HUGE gap of pedagogical information until you're semi-pro.

I agree, but I'm afraid I don't have a solution apart from putting in the time to become sufficiently knowledgeable.

concluded that all coders are elitistic aspergian idiots that don't care if anyone besides their closest friends and idols understand what they do

I suspect there is some truth in that. It may be kinder to say that they don't realize rather than they don't care.

IMHO part of the problem is that the expertise to teach and to empathise with a student is very different from the expertise to write programs.

...R

Mixe:
Yes, I tried reading the .cpp and .h files, but if you're not capable of actually writing your own libraries, those are most often not understandable.

It's sad, but I lean towards thinking that Robin2 is right. Naturally, in my frustration, I angrily concluded that all coders are elitistic aspergian idiots that don't care if anyone besides their closest friends and idols understand what they do- but then why upload your stuff to a public platform? So that can't be the whole truth.

Overall, there's a lot of tutorials for the absolute beginners, but when you've passed the "this is how you install a library"- stage, there's a HUGE gap of pedagogical information until you're semi-pro. It's like beeing told the way by this old lady who lived in the neighbourhood all her life. After the first detailed part there's suddenly big jumps in consistency and skipping of necessary details.

Gratefully accepting tips on where to find tutorials off intermediate difficulty.

+1 for this. Couldn't agree more

Robin2:
I agree, but I'm afraid I don't have a solution apart from putting in the time to become sufficiently knowledgeable.

...R

No, I had no other intention than "putting in the time". Naturally, I haven't. I'm not looking for an easy out, just reasonably comprehensible information. I search and search but I just can't find material to bridge the gap. Every piece of information leaves out crucial parts. I can write the "Blink" program in my sleep, and I have successfully written a code to open doors with a fingerprint sensor and secret knocks, among other things, but when I try to graduate into wireless communication or more complex timed systems, it's like trying to jump across Grand Canyon. Time has nothing to with it.

Which wireless library do you find lacking in examples or documentation? I'm using RadioHead and it seemed reasonably documented for such a complicated piece. Or do you mean wifi?

I agree that this is often a problem. It is nice that the Arduino IDE provides us with a standard way of downloading libraries and of accessing examples, but there's no such standard for documentation.

I try to do better with my Automaton libray (see for yourself here):

It would be a great improvement if there was a way to document classes/methods and members for libraries and have them accessible from the IDE.

Learning complexity takes time...bottom line. Eventually you'll have no problem looking at the .h file and figuring out how the interfaces are designed and intended to be used, but it does take practice. It's impossible to explain it all in one sitting, it just is. The volume of material is large enough that it must be learned piecemeal. The only way to truly grasp it is through practice and repetition, failing and fixing. The good news is that the vast majority of programming involves repetition. When you do the same basic thing over and over again, once you've done it a couple of times you've got it down. After a few hundred times it becomes instinctual.

My suggestion is that you open the .h file and start reading it. When you get to something you don't understand, post a question and get someone to explain what's going on. I will do that for you if I can. Then you'll learn then next piece and eventually you won't need to ask anymore. Frankly, if you can understand and write working code without using a library, then it won't take much more effort at all to understand what is being done by a library-- which in the end is just a method of taking related chunks of your code and separating them out into different files to make things more organized and maybe reusable in some other project. The code isn't any different. I mean it doesn't follow any different rules just cuz it's in a library file. It's still C++ through and through, just not all stored in one main program file is all.

Something you have to resolve yourself to accepting is the fact that hardly anyone documents code for free. It isn't really worth it. It has to do with laziness, not conceit, by the way. Be wise and learn to read it yourself so you can do without the docs, otherwise you are in for an eternal struggle. Just like with anything that requires you learn how to do it. If you refuse to learn how and try to stumble along anyway, it makes doing it necessarily unreliable and confusing and hard to repeat. Don't believe me? Try running a bulldozer without learning what all the buttons and levers do.

What you are trying to do is, in fact, much easier than being able to understand the entire library. You just want to use the library functions and are unconcerned with the details of how they work. All you need to be capable of is looking at the .h file and identifying the functions defined in there and the parameters they use. Then try them out to experiment and find out what works and what doesn't. So initially, just look for function prototypes and you'll come up with a list of possible actions you can invoke. Functions always conform to this prototype structure:

returnValueDatatype functionName( parameter list );

so that's the pattern you want to look for in the .h file. Locate all of them and you'll have a good understanding of the interface available for you to use. Then just experiment if there is no doc. Post specific questions when you get stuck. Pick it up a little bit at a time.

You haven't really asked a question in your post. It is more of a rant really. And so you are not likely to get any sort of answer that solves your dilemma. We can commiserate with you cuz we went through the same thing, but we can't insert the understanding into your brain through some sort of osmosis process. I can tell you for sure there is absolutely no "trick" involved with reading libraries. It is no different than reading any other C++ code. Just a basic understanding of C++ is all that's necessary to do what you are wishing you could. If you ask a specific question I think you'll get a more concrete useful answer that actually furthers your understanding and capability to figure these things out yourself. I assume that is your goal.

Stated another way, don't ask how to assemble a jet aircraft. Instead start by asking how to assemble a wing or a landing gear or some smaller piece that can be reasonably explained in one short sitting. Find something specific you don't get and ask about that first. Trust me, the rest will fall into place as you go...and it will get easier and easier to understand when you progress this way. We can't help you step through it if you don't move in reasonably small steps. Walk before you run and all that sage advice. "How do I read a library?" is far too broad a question to be answered...especially in a forum environment, but even in a face-to-face situation. All you could hope to get by asking such a thing is an equally broad answer: "By decoding them line by line".

Mixe:
but when I try to graduate into wireless communication or more complex timed systems, it's like trying to jump across Grand Canyon. Time has nothing to with it.

As others have said if you ask a question about a specific library you will probably et a lot of advice very quickly.

Jumping the Grand Canyon is impossible AFAIK. But I think you will be surprised how quickly your ability builds up to enable you to make sense of things you now find overwhelming. A very important part of computer programming is recognizing patterns as that enables you to translate learning in one area to another area. @AxeMurderer's returnValueDatatype functionName( parameter list ); is a good example.

Reading lots of code also helps enormously as it introduces you to concepts and ideas that may not occur to you within the context of your immediate needs.

...R

Well, phew, thanks everyone. A lot of good answers, peptalks and advice. I really didn't ask for anyone to actually solve anything for me, just if there was a way to figure out the functions of libraries that I had missed. But there wasn't, it seems. So then, admittedly, I started ranting :).

I've gone through med school, I know about grinding and repetition, trust me. I'm just used to having better material to deal with. But the pedagogical geist and willingness to help in this thread and in this forum is heartwarming and inspiring! And yes, AxeMurderer, I might very well take you up on that promise to help :slight_smile:

No more rants, just specific questions from now on

Tinkerspy:
It would be a great improvement if there was a way to document classes/methods and members for libraries and have them accessible from the IDE.

YES! YES! I love it when you talk dirty! And your library was a wonderful example of How It's Done. Perfectly documented and presented. Good job, hats off, due respect!