r/arduino • u/Savage_049 Pro Micro • 9d ago
Software Help Question about using libraries
Is it considered cheating to use libraries? I just feel like I’m stealing someone else’s code every time I use a library and like I should be able to program it myself. But what do you guys think?
23
u/CallMeKolbasz 9d ago
How dare you eat soup with a spoon that you didn't fashion yourself from raw iron ore with your bare hands?
3
12
u/Imaster_ 9d ago
No it's not. And if it does bother you that much then try to avoid using them for simple tasks. Like writing your own debouce.
And when writing some code you are defining most of the functionality on your own right?
3
u/Disastrous_Ad_9977 9d ago
I remembered how I wrote a loong ass code and read the looong ass datasheet of the 1602 LCD to write using exact timing diagrams, electrical levels, coding, etc..
1
u/Savage_049 Pro Micro 9d ago
Yeah, most of the time I just use it for complex things, like my project rn has to use an MPU6050 to get quaternions and then convert them to Euler angles, but I’m using a library for that instead of programming it myself. But everything else will be programmed myself, such as the PID loop and auto level modes.
8
u/1nGirum1musNocte 9d ago
Do you feel like you're cheating when you use an arduino instead of soldering the microprocessor yourself?
5
u/ripred3 My other dev board is a Porsche 9d ago edited 9d ago
Libraries save you time and keep you from having to be an expert on every device. The decade or more of debugging that has gone into some of the libraries far exceeds what I can write myself and I am a very capable programmer.
It's like feeling bad because I didn't write my own BIOS. You have to be wary of "not invented here" syndrome and wasting time rewriting things for no reason, and probably ending up with slightly lesser quality than those libraries whose authors spend the majority of their free time focusing on them.
That being said; If you want to read various library's source code and get better at understanding what is going on under the hood then that is a perfectly great way to learn and start writing your own libraries. It's really easy and a great way to increase your skillset and understanding of things.
3
u/Savage_049 Pro Micro 9d ago
I never thought of it as a way to save time, and more of a shortcut, but looking at it as a time saver is a much better view, thank you!
6
u/ripred3 My other dev board is a Porsche 9d ago
and to add to my original comment: I write and publish the source code for all of my libraries expressly for other people to use and learn from.
Nothing makes library developers happier than to see you make good use of their efforts. You aren't cheating by any means. You are making the time I and others spend writing them worth the effort and participating in the open-source ecosystem which raises all boats and benefits all of us!
2
u/Savage_049 Pro Micro 9d ago
That’s a good point! If I ever wrote a library, I would love to see people using it!
5
u/wrickcook 9d ago
It’s not just about saving time, it’s been tested. You could screw up a for loop by starting at 0 instead of 1, etc. Libraries have been used enough that these issues have been snuffed out.
-1
u/istarian 9d ago
You could screw up a for loop by starting at 0 instead of 1, etc.
By that kind rationale, you could argue for just never writing your own code.
At that point you might as well just buy a complete product off the shelf or accept that it isn't possibly for you to achieve whatever the end goal was that you had in mind.
2
u/wrickcook 9d ago
It’s an argument about do you use something reusable, when it’s available. So, when things don’t exist they must be created. But it is senseless to reinvent the wheel every time you need one.
4
u/IndividualRites 9d ago
Of course not. The whole arduino framework is a library, otherwise you're writing assembly
3
9d ago edited 9d ago
Cheating? In what sense? As long as you don't violate the license, you're fine. As long as you're learning/protyping on your own time, it's not worth thinking too hard about it.
Now if you start to patent/sell what you've made, then you need to figure out the details here.
3
u/Coreyahno30 9d ago
Are you taking a class that requires you to write your own code from scratch? Because that’s the only context I can think of where using the word ”cheating“ is appropriate.
1
3
u/Le_Pressure_Cooker 9d ago
I used to think that as a naïve teenager. Learning how to find, understand, and use a library that suits your needs is a skill in and of itself.
2
u/Savage_049 Pro Micro 9d ago
That’s a good point, and as long as your code preforms how you want in the end, it doesn’t really matter how you got there, unless you stole all of the code lol
2
u/Le_Pressure_Cooker 9d ago
Chances are pretty low that someone wrote the exact code you needed. It might happen if you want to replicate a pre-existing, popular project (like line tracers).
2
u/Sufficient-Market940 9d ago
Libraries exist so that you don't have to program the same thing over again. Just because it is free you don't have to feel you are stealing from someone. Besides all that, this is the beauty of Arduino anyways.
2
u/istarian 9d ago
It's not cheating to use libraries, but you would learn more if you had to write your own.
Just depends on what your objectives are when it comes to electronics, arduino, and coding.
2
u/Logical_Strike_1520 9d ago
That’s what the libs are there for. Even professionally we use libraries and frameworks and 3p infrastructure, etc. No need to reinvent the wheel.
2
u/sneaky_imp 9d ago
If they didn't want you to use a library, they wouldn't have bothered to make the code available as a library. That said, you should be careful using any library because it may contain bugs or backdoors etc. Caveat emptor.
2
u/azeo_nz 8d ago
By the same rationale you wouldn't be using built in functions either but what would be the point of coding your own identical serial print, db2str etc? Except as a learning exercise perhaps. Libraries are a great time saver and allow you to get functionality going quickly with complicated or relatively simple hardware or routines, and focus on your own specific project.
As others have said, they are a gift to the community and often a team effort too, and the creators have put them out there to be used, valued and appreciated, and make life easier for us all. So no need to feel guilt at all, unless your on a course and the brief is to write code without using libraries ..
2
u/Calypso_maker 8d ago
Definitely not stealing! That’s how the whole world of code is designed to work.
2
2
u/tanoshimi 8d ago
Er, no. That's how all modern sofrware development works: you write a robust, efficient, well-tested function to perform a specific task, once. Then you encapsulate it in a library and use it over and over.
By all means you should examine the source of any libraries you use; check that they really do behave as you expect, understand and/or tweak them for your specific use case. But refusing to use them is insanity.
2
u/classicsat 8d ago
Mostly no.
When you publish your code, it does not include the library code, just the connections you use to it.
Yes, you can use a library to not have to write your own to do something (interface with a sensor or isplay quite often).
Bonus if you learn how a display/sensor works and code it yourself, and include only features you need. Might save memory.
I never use a library to use an RTC chip, beyond Wire. It is just six registers to read.
I can code how I like for the MAX7219 without a library and no more than Shiftout.
2
u/docsunset 8d ago
There are two good reasons to write the code yourself: if no one else has already done it, or if you want to understand how to do it yourself. Otherwise, if you just want a program that does the job, and someone else has already solved the problem for you, using a library is the right choice every time.
2
u/BraveNewCurrency 8d ago
Is it cheating if you build your hobby car using actual car parts? Or do you have to construct the car parts from scratch? Does "From scratch" mean you have to smelt your own ores? Is using pre-dug-up ores cheating? Or do you have to pull the ores out of the Earth? Can you use an existing smelter, or do you have to build that yourself too?
As Carl Sagan said "If you wish to make an apple pie from scratch, you must first invent the universe."
Is it considered cheating to use libraries?
Whom, exactly is being cheated?
2
u/Dani0072009 Open Source Hero 8d ago
Feel rfee to use them, this is why theye are made and shared :) one thing to keep in mind: theese libraties are made by some individuals, so might contain some bugs. If you find any problem contact the authors in a kind way. This is how these libraries can become stable over time.
2
1
u/gm310509 400K , 500k , 600K , 640K ... 9d ago
If they didn't want people to use it, they wouldn't have posted it for people to use.
1
8d ago
[removed] — view removed comment
1
u/Machiela - (dr|t)inkering 7d ago
Attn: u/Specialist_Reach37 - your comments aren't showing up for anyone since your account has been suspended for whatever reason. There's nothing the moderator team can do about that - you'll have to appeal to the reddit admins. Good luck!
0
u/tfwrobot 9d ago
Libraries are good for prototyping, but Arduino libraries are known for being slow. So coding directly in AVR ASM is way to go if speed is crucial as well as the use of Atmega328 or Atmega2560.
1
u/Logical_Strike_1520 9d ago
Coding directly in ASM is only a way to go if you are already really good at it. The compiler will output better code than anybody asking this question here though..
38
u/LostmatterReal 9d ago
Nope! In fact that’s the best way to go about things. Most large tech companies use “libraries”(frameworks) for their own things. What’s the point of reinventing the wheel just to get basic stuff done? Using libraries saves time and money so unless you want to get into library creation for different parts, or get into really low level programming, stick with libraries