Laying out code. Which order matters?

You'll have to go pester a CS Prof about that one. They love dealing in the minutia of defintions.

this isn't a legal issue

just trying to describe some programming practices that are generally thought of as very good that can be used without understanding classes or using some well recognized object oriented programming language.

and the Cargill book i mentioned earlier shows how a program using classes can be poorly written.

at least the Stroustrup's 3rd ed. described how C++ could be used to write programs in several different programming paradigms other that OOP

Using Arduino IDE for simple hobby projects does not require understanding OOP. However, libraries are OOP and require a level of understanding to make the best use of them. To do significant changes to a library or to create a new one, one must have good understanding of the programming concepts involved.

The question then becomes how much effort do you need towards building your understanding for your own needs. Only you can answer this.

I recommend starting with separating out your existing big sketches into multiple small pieces with the Arduino IDE Tab option (upper right corner, square with downward triangle, IDE 1.8). Everything global (includes, declares, variables, all other things required above Setup), the Setup, and the Loop must be in the original tab. All of those other functions are the things that can go into the other tabs. Makes finding them easier when they are organized into multiple tabs.

I like to create many simple functions and use them whenever they are needed. My Loop() will only contain a few function calls to minimize the size of the first tab. The main goal is to make editing the sketch later much easier. “Good programming” really means easy to understand, edit, and reuse later.

The quickest way to learn the difference between procedural and object-oriented programming is to design and code a BlinkWithoutDelay example for more than two leds.

not sure what your trying to say

wouldn't you use object oriented concepts if you weren't using classes? even if the language does have classes (not sure, but Python)?

No, some useful information may still come along. :crossed_fingers::rofl:

1 Like

Really ?

1 Like

i don't think anyone is suggesting assembly language must be OOP language because it ultimately implements a C++ language, nor that C must be an OOP language because the initial versions of C++ were translated into C.

it is YOUR thread, you can moderate that thread.
You can guide the responses in that direction you want.
Just ask something you are interested in.

Yes, when the elephants dance, it is the grass that gets trampled.

One thing I hope is clear is that you need to take things your friend(s) tell you with a grain of salt, sometimes more than that.

Beware of the words never and always and in general any extreme view point.

There are conventions it makes sense to try to adhere to. Other than that there is tremendous latitude and the possibility of coding being less than slavishly following of someone's idea of right and wrong.

a7

3 Likes

At the time of typing it, that was my understanding. All libraries use encapsulation, an OOP concept. My point was that OOP concepts could help the OP understand libraries. I have no interest whatsoever in debating the intricacies of structured and OOP programming differences.

YMMD :+1:

Again. Really ?
A library can be as simple as a collection of useful functions (or even a single function). No OOP, no encapsulation, just plain code

4 Likes

There is. This statement is proof of the misconception that humans know better. Computer programming is in its infancy, like Sonja Hennie compared to Tai Babalonia, with programming still referred to as "computer arts" because of what you mention. Compilers error-check the mess created by error-prone humans... to guide the poor souls toward the One True Code, toggling its trillion transistors in an electronic "tsck." One day, it will happen.

Right!

To @baffled2023’s original question, classes are simply a tool available in the box of OOP languages. Deciding on the appropriate place to use them depends on the preferences, skill, and judgement of the craftsman. You certainly don’t need to build a bridge to cross a river once. On the other hand, a class with a singleton instance may be just the right construct in a given situation.

I’d say you got the answers you asked for, perhaps not the answers you were looking for :stuck_out_tongue:

If the philosophical discussion that has ensued is not for you, ask a new question or better yet, post some code for critique.

Although you may not need classes, it might be interesting to write a few really simple ones so you can see how they work.

we are getting far from OP's original ask....

What's a variable?

Joking...

Thanks all. I will continue to try and improve my skillset

My original comment included my misunderstanding about what constitutes OOP, a quick google search revealed that. The second comment was intended to clarify the point I crudely stated the first time “Learning OOP will help with understanding libraries.” The semantics of OOP is not my expertise and not something I care to include.

Please enlighten me on how my suggestion to learn OOP programming to better understand programming should have been worded to meet your approval?

Then it failed to do so
Let's keep it simple. Many libraries use OOP to implement their functionality but they don't have to

1 Like