Learning OO languages

@The_Elf You might like Python. It’s pretty much as you say.

But, if you hate curly braces for block definition, there are some Algol-derived languages like TAL that have you write out the reserved words BEGIN and END around every block. After a while you get where you can type them really fast. Then after a little longer, you get where you can’t type them correctly at all.

2 Likes

Yes, what @RackedBrain said, if you really dislike curly braces then python might be your choice.
However, replacing braces with indents isn’t going to save much space in the source code.
I use python 80% of the time now and I miss braces.

For help on learning OO, I would look to OO design first before picking a specific language.
Find a simple problem and try to design the solution using object oriented principles. And if you find you can’t then perhaps the problem doesn’t need an OO solution.

There are also ebooks and online course. MIT has some: https://ocw.mit.edu/search/ocwsearch.htm?q=object%20oriented%20programming.

Think yourself lucky though. I work with some people who seem to only think in OO and put every line of code inside a class which ends up with a bloated piece of software.

2 Likes

Yup - been there with PASCAL. After that, the curly braces of C were a relief!

And TBH, I definitely prefer curly braces to indentation - I like logic to be separate from formatting / style.

I generally comment my closing braces to make sure I recall what conditional block or loop they close - makes things lots easier to debug. Once you get the hang of the “jump to corresponding brace” shortcuts, navigation is a breeze - far easier for me than messing with indents - easier to mess up :frowning:

I can relate to the semicolon gripe, though. In most of my code, the end of a line is also the end of a statement, so it would be far more economical to define end-of-line (or the beginning of a comment) as the end of a statement (unless the end of the line is an opening brace to open a new instruction block, of course). For multi-line statements (mostly optical reasons), you could use a line-linking character like “_” or explicit “block markers” for begin and end (e.g. array initialization). That could actually make things a lot easier. Kotlin has gone there and made semicolons optional…

2 Likes

Just thought I’d throw it in here, I can program in most high level languages and understand the syntax even if not fully familiar, but Ada (which my team uses in a safety related application) is one I really fail to understand (but that is what my team is for! :slight_smile: )

1 Like

I coded Cobol, Fortran, and Basic for a college computer information degree in the eighties. I already had enough college education under my belt, but an associate convinced me it would somehow boost my already lengthy music education. I learned a lot, but it panned out to be a waste of my time.

2 Likes

@Torsten Exactly. And SQL queries. It’s always the ;

I was involved with training client admins so I always wrote T-SQL queries for maximum readability even though they were many more lines:

SELECT 
 c1.accountno
,cs.contsupref+cs.address1 AS Email
FROM 
 contact1 c1
 JOIN contsupp cs
  ON c1.accountno = cs.accountno
WHERE 
 cs.mergecodes = 'E'
 AND c1.state IN 
('ME','VT','NH','MA','RI','CT','NY','NJ','PA')
GROUP BY
 c1.accountno
,cs.contsupref+cs.address1
1 Like

10 PRINT “HELLO WORLD!”
20 GOTO 10

Now that’s a clean, readable programming language! :smile:

Don’t take me too seriously, guys. I’m just a dog barking at the moon!

3 Likes

Aah, the BBC micro…

P

1 Like

BCC Micro?!?! Pah! Commodore 64 here, mate. :grin:

1 Like

That’s a cool BASIC program and all, but can you post a video of yourself doing a poor job of typing it into an FPGA emulation of a machine that you made yourself?

(My holiday hacking project from last year)

3 Likes

I whiled away many a Sunday afternoon typing BASIC programs into my ZX Spectrum

P

1 Like

I’ve made an ‘Arduino/C++ inside’ box, that works very well with Cantabile…


Details soon… :sunglasses:

But no, I rely on a Raspberry Pi and Retropie for my C64 fix (though I still have a fully working C64/floppy drive sitting around now gathering dust…)! :smile:

1 Like

Why do you have a second red button? Hope it’s not for nuke from orbit. :sunglasses:

2 Likes

Double red = Backup button for when 1st red doesn’t work. :grin:

1 Like

New thread on its way…

1 Like

Looking forward to learning more about how you put the unit together.

1 Like

There’s a bit of info in my other thread as to how it functions. Essentially it’s an Arduino board, some arcade buttons/lights and some C++ code that does the clever part.

1 Like

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.

3 Likes

I think I was reading Codd and Date when I first realized all software engineering books were basically that. :nerd_face: