Dear Mr Elf,
C64 assembler and BASIC? Respect. OO? That’s a bunch of people selling you a book about things which you know well by other names, largely on the basis they don’t trust you to manage chunks of RAM for data manually and find it hard to crib your code.
So, permit me a simple map of terms which will help you translate, on “they say, you know it as” basis:
An object? A buffer of length N 8bit bytes. You know your offsets, you just want the chunk of RAM, but OO insists you map it all out with names before you use it. Where is the fun in that?
A field? A name for a particular byte at a known offset into your N byte buffer. In OO each offset is not only given a name, but a type, largely to establish how many following bytes are needed. But you know that anyway.
A property? A SUB devoted solely to accessing a particular byte (and bytes following) at a known offset in your buffer, which just complicates things, but means you are now into name-casing rules and brackets. Yay.
A method? Ah, that would also be a SUB, sometimes with a return value. You generally need to pass variables, or copies of variables, or the address of your buffer, or a reference to your buffer – but it’s open season.
A static method? Yep, another SUB, where you have to definitely have to pass in the address of the buffer you want to work on. It is not allowed to know anything internally, because that would be cheating. It’s also visible to everything, which makes it global.
Word of warning - you will find using words like “global” and “variable” (especially one after another) really, REALLY upsets OO people, if it does not send them into a complete meltdown. But call global things “static”, and they’re good. (Just don’t let on you know they are global variables.)
A class method? Ah yeah, a SUB, which accesses a buffer or other program variables outside the SUB without the annoyance of having to pass them in, provided it’s close by. Mainly. It’s kinda optional, so more a style thing? A style people are calling this “functional” these days. A function that is functional? ‘Fraid so. (Cue another book.)
A class? A cute name for the map of named offsets/lengths into your buffer of n bytes. On the heap. Sometimes with class methods, and static methods (remember, those “global” things I mentioned – shh) neatly set out between brackets. Often one class per file.
A struct? A map of named offsets/lengths into your buffer of n bytes. On the stack. Sometimes with class methods, and static methods (remember, those “global” things I mentioned – shh) neatly set out between brackets. Often one class per file. So… almost identical to classes. And, let the arguments begin. (Another book.)
Int / int32? 4 consecutive bytes thought of as one biiiiiig integer number. There are other types of numbers besides ints. Allegedly.
A C++ pointer? Just like in ASM, an address which points to the start address of your N byte buffer.
A C++ reference? An address which holds an address to the start address of N your byte buffer. Spotting a trend here? A reference to a reference to a reference? Well, most things are possible in C++, but that would be (another book) . A reference is considered slightly safer than a raw pointer. Changes to references won’t kill your memory map and leak RAM. Although some enterprising soul probably will find a way. That’s the power of code, right there.
Pointers and references are the best bits of C/C++, unless you mess up your memory somehow. Then you will rue the day you realised you could play calculator with memory addresses and a variable called i. So, best ask the O/S for that chunk of RAM using a “malloc()” and “free()” it at the end (in non OO C). Or in C++, use “new()” and “delete()”. The deal is you get to code, the O/S gets to mind your addresses for you. No, the O/S won’t tell you where it is. Just ‘cause you might want to mess with it, and well, it is widely believed the universe will end, and BADLY, if you do.
If that’s too scary, use C#, where pointers have been entirely disavowed/demonised/banished due to no particular fault of their own. If that feels too safe, still use C# but compile your code with the “unsafe” option, because it puts pointers and references back on the table, and still means you can avoid using C++ header/code file project chaos. It gives you access to low level stuff like drivers, O/S calls, callbacks, serial data and, you know… more of the embedded things you know and love.
Want a sneak peek of C#?
var myInferredAndUneccessarilyLongCamelCasedVariable = new ClassName();
Another style thing for sure, but in C#, that’s your memory reserved in the shape of the map “ClassName”. Go with it - classes start with Capital Letters, and instances, lower case.
The rest of OO is just semantics, tidiness, and about the worst infection of ridiculous acronyms you have ever come across, shy of working in Navy Ops. (More books.)
Oh - do watch out for advocates of something called “Test Driven Development”. This is really a PR stunt in how to add in a 50% margin of error in delivery estimates, so there is something big to eat into when running late. You can spot the devout easily enough – they talk about T-shirts, Fibonacci, regression testing (which I think is working out how to run code backwards, I could be wrong?). They use phrases like “sprint” and “continuous integration” and will go on about some chap called Jenkins. Crucially though, they get paid twice as much for taking twice as long to delivering the same functionality, and STILL manage to foist the real testing on the user community. This is a BAD HABIT to get into, so avoid them, because it’s the new religion, and like a virus it’s catching. We all know software is never really finished, but quietly abandoned later, once the complaining dies down. As if passing 100 tests was any kind of definition of “working”.
So, suitably armed, I trust your development path is now clear, and that your decision to stay with embedded (and laugh at web and app devs) serves you well. In MIDI 1, pointers, and 56k of 8bit 6502 ASM we trust. (Principally because these things actually worked.)
Tongue firmly in cheek.