Author Topic: Why most people say "vendor supplied libraries are bad"?  (Read 14036 times)

0 Members and 5 Guests are viewing this topic.

Offline NorthGuy

  • Super Contributor
  • ***
  • Posts: 3251
  • Country: ca
Re: Why most people say "vendor supplied libraries are bad"?
« Reply #100 on: June 26, 2020, 03:50:40 pm »
Again, if i use the Atmel ASF as an example once more: It first became Atmel Start (ASF4) which became MPLabX which became Harmony, all this within maybe 4 or 5 years, i don't know. It also happened to ST frameworks. So there is a continuous need for rapid update.

You're making my point. If you worked on the hardware level, there wouldn't be so much of a change.

People want libraries because they don't know what's inside of them. They believe there's something inside which is guaranteed to be done properly, perhaps giving some kind of moral support, or perhaps even some kind of magic.

But then you get bugs, you start to dive into the library code, and you see that there are many things that you don't need, which perhaps, may be removed. After you remove them and look at what's left, you see that you can remove more. Finally, when you dig to the end, what's left is so small - no magic, nothing like that, just a small amount of code which actually do things, and even that small piece can be improved. Then you wonder, why did I ever need to dig through all that while I could just write few lines of my own code instead. This happened to me so many times in the past.

Of course, there are bigger libraries which provide useful services, such as lwIP, which you probably should use. However, I don't think that if you spent couple days writing your own TCP implementation, it would be inferior to the TCP implementation in lwIP. But you would get something in return - such as you could choose your own storage model - fixed circular buffers, linked list of fragments, or whatnot. You would also get full control over the window advertisement, get better speed perhaps. You would be way ahead of that guy who tries to make his TCP work faster by tweaking parameters of the library he doesn't know anything about. And you would be able to do special things which the library simply can't - such as acking a lost packet if it is already obsolete to your app, instead of stalling the connection. But if you just want the library for your latest IoT project, you would never know how TCP really works and you would continue to believe that whatever library you have chosen provides the most efficient access to the Internet.
 

Offline dietert1

  • Super Contributor
  • ***
  • Posts: 2414
  • Country: br
    • CADT Homepage
Re: Why most people say "vendor supplied libraries are bad"?
« Reply #101 on: June 26, 2020, 04:18:26 pm »
Concerning the UART example: More recent MCUs include hardware to protect hardware settings after the init phase, during normal software execution. So when using things properly you cannot just write a baud rate register without unlocking that hardware protection first. Also you have a choice of about ten clock sources, each one with its specific frequency and power saving behaviors. Also you want to configure wake-up by the UART receiver. So that UART gets a bit more tricky.

The ATSAMC21 Canbus quickstart example included a UART connection via the debugger CDC channel. I just had to find out the actual baud rate and setup a Hyperterminal window. Then a menu appeared on the terminal. That worked on the Explained Pro kit i got for development, hope i can wire it up on the first prototype with the other MCU i will be using. One of the difficulties i had was finding out actual pinouts for the SPI connection. Those MCUs have two levels of pin multiplexing for the Sercom pads/pins.

Concerning optimization: That's a beginner's mistake to get trapped into optimization before getting results. If there are performance issues, it is usually very easy to solve by rewriting a small piece of the application later on.

The use case i was proposing as an example was Atmel Studio 7.0 with ASF3. It is outdated but that's what i already had on the laptop. Maybe i will install Harmony and see what that is. I definitely want open source.

Regards, Dieter
« Last Edit: June 26, 2020, 04:24:17 pm by dietert1 »
 

Offline thm_w

  • Super Contributor
  • ***
  • Posts: 7236
  • Country: ca
  • Non-expert
Re: Why most people say "vendor supplied libraries are bad"?
« Reply #102 on: June 26, 2020, 09:09:05 pm »
But the elephant in the room is that a typical UART peripheral usage implementation, even in a modern ARM MCU, is below 10 lines of code!

Maybe three lines of turning the peripheral clock on, and connecting the UART to the IO pins. Which is something a library does not magically do for you; you need to still know how to do it, with another library call which is very likely more than 3 LoC.

Then approx. two lines to configure the UART: enable, set baud rate register.

Keep in mind DMA UART functionality would take more than 10 lines of setup, but its still a single line library call + callback.
STM32 lib with cube will do all the clock configuration for you btw.

People want libraries because they don't know what's inside of them. They believe there's something inside which is guaranteed to be done properly, perhaps giving some kind of moral support, or perhaps even some kind of magic.

But then you get bugs, you start to dive into the library code, and you see that there are many things that you don't need, which perhaps, may be removed. After you remove them and look at what's left, you see that you can remove more. Finally, when you dig to the end, what's left is so small - no magic, nothing like that, just a small amount of code which actually do things, and even that small piece can be improved. Then you wonder, why did I ever need to dig through all that while I could just write few lines of my own code instead. This happened to me so many times in the past.

Or you know, they want the library because they know whats in there but realize they cant write all of those features in a matter of hours that it would take to understand the API?
There is zero reason to start stripping out code from a library unless you are starved for space or you want to modify the functionality of the library.
If you are working on a space constrained project, trying to keep costs low, then of course that is another valid reason to not use vendor libs.
But for $3 you can get a micro with 256kB of flash. Its not worth saving 50c on a one-off project if your goal is getting something working asap.
Profile -> Modify profile -> Look and Layout ->  Don't show users' signatures
 
The following users thanked this post: nctnico

Offline NorthGuy

  • Super Contributor
  • ***
  • Posts: 3251
  • Country: ca
Re: Why most people say "vendor supplied libraries are bad"?
« Reply #103 on: June 26, 2020, 09:56:24 pm »
There is zero reason to start stripping out code from a library ...

If you interested in my reasons, I wanted to understand how things work. I was young and inexperienced and had a great deal of admiration for the software around me. Now I don't :(
 
The following users thanked this post: thm_w


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf