Notifications
Clear all

[Closed] Object Oriented techniques - Example 1 - "Hello Class"

302 Posts
10 Users
229 Likes
20.1 K Views
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7008
 

@will Thank you will. I assumed everyone knew the names had to be meaningful, and YES the comments belong inside the routine.

On this we can totally agree, as well as your final para. I hope Bill is listening and at least tells us his take on this 'teaching a language' topic.

I am actually beginning to lean towards NOT here, take it to the C++ forum because I don't think but could be wrong that it can ever be truly separated out from the normal stuff.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
Biny reacted
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1122
 
Posted by: @zander

@byron I disagree

Many do 😀. In this case, the idea was to illustrate that 3 LED's were being flashed independently without creating a class and instantiating multiple instances.  I thought that showing a separate function of each LED would help illustrate better what was taking place.   Its meant to be illustrative, not final code.  I probably failed 😪 


   
Biny reacted
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7008
 

@byron I believe that almost any time you write code it should be your best code. It reinforces good habits.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2535
 
Posted by: @byron

Many do 😀. In this case, the idea was to illustrate that 3 LED's were being flashed independently without creating a class and instantiating multiple instances.  I thought that showing a separate function of each LED would help illustrate better what was taking place.   Its meant to be illustrative, not final code.  I probably failed 😪 

You didn't fail Byron. The fact is that wrapping an LED in a class is just such a pointless exercise in the first place.

Anything seems possible when you don't know what you're talking about.


   
Biny reacted
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1122
 
Posted by: @zander

I believe that almost any time you write code it should be your best code. It reinforces good habits.

The only good way to show that, in this instance, just one function would better illustrate the point of a comparison to using classes is to actually produce just one function for illustration.  Its up to you to if you wish to show this.  Clearly, for you, the point was not well illustrated.  And in due consideration of your comments, I still feel the post I made illustrates what was intended and therefore is 'best code'.  


   
Biny reacted
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1122
 
Posted by: @will

You didn't fail Byron. The fact is that wrapping an LED in a class is just such a pointless exercise in the first place.

Indeed putting an LED in a class is pointless, but the article on this was endeavouring to illustrate that the Arduino could multitask and using LED's blinking at different rates as an example.  So the article had some merit, and I was just illustration some multitasking without using classes.


   
Biny reacted
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1122
 
Posted by: @will

I like to keep all the routines short so that I can read them as a unit in one page (or less).

Yes, the very point I was making, that in this instance 3 short routines may be better than just one where on has to remember the values passing in to make sense of what is happening inside of the function.  You like is short, sometimes I prefer long, though in general I would agree with your comments.

Posted by: @will

By the time everybody has their say about it, we've swamped out the recent posts column on the right with stuff that's not relevant to the vast majority of forum members.

Yes, so I will say no more. 😀 


   
Biny reacted
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7008
 

@will I disagree, as much as I am not a fan of OOP, I think the LED example is more pertinent to this audience than the usual shape example.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7008
 

@byron Ok

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7008
 

@byron OH, I missed that it was multitasking. Now I will need to find the code you posted somewhere in this 11 page thread. Did you use the kernel calls for tasking, or is there a high level call I am unaware of.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7008
 

@byron As someone who studied the habits and work patterns of programmers and was a follower of Dr Ben Shneiderman's work, I am very sure short subroutines go hand in hand with short term memory. I spent years getting 300 programmers to stop writing war and peace and instead create functional code.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1122
 

@zander 

Dear Ron, I'm not clear at all what you are meaning.  I make this suggestion.  Wire up 3 LED's to your board and make them blink at different rates without re-reading the article where this was achieved using classes, or looking at my code where this was done with the Arduino language as shown in the Arduino docs and tutorials that do not venture into C++ classes.

Then, when you get your version to work, and it should not take long (I spent about 20 minutes on the task, and some of that was trying to locate a board with an onboard LED so I did not have to wire anything up to test the code) then lets see what you come up with.   Its a fun exercise if your up for it, and will illustrate to you if you are lacking in any coding expertise to achieve this.  I suspect you will find this a walk in the park, and then we will have the masters way, the c++ way, and the byron way.   No prizes and no winners, just alternatives.


   
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1122
 
Posted by: @byron

make them blink at different rates

And I should have said 'blink at different rate simultaneously', but I'm  just stating the obvious or there would be no point to the exercise.


   
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7008
 

@byron simultaneously is a tricky concept. An ESP32 contains two independent CPU's. That means it can be executing 2 independent instructions at the same time. It may have a dozen tasks on each CPU, but at the machine instruction level only 2 are being executed. If it does it fast enough it may seem like many tasks are running, but in fact the hardware only supports 2. Many modern PC type computers also have GPU's and they can execute one or more instructions in addition to the CPU cores that we traditionally call the CPU. Sorry, but I first learned the hardware so I know that all the software sauce in the world can not cause more than one instruction per processor to happen at the same time.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1122
 
Posted by: @zander

know that all the software sauce in the world can not cause more than one instruction per processor to happen at the same time.

That would indeed be the situation, and lets not complicate the task by using different cores.  Just one thread, just one single core microprocessor. So the task is, how to make it appear to the user that things are happening simultaneously is it not.  Well I know you know that at 1 million time per second (or more) for each instruction it can appear that more than one task is being performed.  And we know thats all there is to it.

This post was modified 2 years ago by byron

   
Page 11 / 21