I’ve been bemoaning my inability to get to grips with modern ‘OO’ programming languages. I’ve created this thread in case anyone wants to chip in with their experiences/thoughts.
Your OO endeavors would have more impact if you did a deep dive to build your core competencies which would result in synergies that at the end of the day would move the needle to the bleeding edge.
@dsteinschneider Scott Adams hacked your forum account!
Try Java instead; it keeps the best bits of C++ and throws out all the bits that nobody understands and/or abuses like operator overloading, polymorphism….
And it is (apart from a few gotchas you can code around) cross platform. Not suited for everything but as a free language you can get a lot of mileage out of it unless you want the absolute in performance (like Cantabile).
I don’t know what those things are, but I suppose that’s part of why OO languages leave me cold - too many hip business-meeting-from-hell, ‘blue sky’, ‘outside the box’, ‘stick a pin in it’, ‘put it on the back-burner’ buzz-words, and an unhealthy obsession with brackets! I’ll get some obscure error and all it will mean is that I have a curly bracket missing somewhere completely unrelated to the error. Grr!
This is why I admire people like Brad who seem to be able to do something useful with this type of language - I can do some of it, but it all gets so unwieldy very quickly (especially the brackets), and the resulting programs (unlike the BASIC and COBOL - even assembler - that I grew up on) are unreadable to me - even if I was the one who coded it!
Anyway, Java won’t help me with my Arduino, unfortunately. I did have a stab at Java long ago, but it was painfully slow, so no use for time-critical programs.
And I did try to write a simple VST plug-in during lockdown. As soon as I tried to combine Juice and Visual Studio with the very first ‘Hello World’ program the compilation failed and I was seeing messages about stuff missing… Life’s too short for all that. Abandon ship!
Obviously horses for courses. I like the idea of object orientation compared to “straight” procedural languages. But C++ can be contorted beyond comprehension as can C (have you ever seen the competition for the most manually obfuscated, but still syntactically correct valid C program?).
As I am an idiot who cannot sit still(!), as well as a demanding day job, music and home life, I still program for an intellectual challenge to keep the grey matter active, and have been programming Java based librarians for my synths since 2001 and get a modest “toy fund” income from them. Not in the same league, I am sure, as Brad and Cantabile, but useful to me, and I get the librarians with the features that I wanted for my synths that I could never find on the market.
Why Java? During 1999-2000 I had written utilities in C on a Commodore Amiga (my platform of choice back in the 80s and 90s) for the DX7 (resurrecting corrupt DX7 files for people on the old DX7 mailing list including for a certain Mr B. Grey of Greytsounds fame) and my Yamaha EX5 (once you have manually remapped 256 voices to point from FLASH Waves to DRAM (element by element, voice by voice), you will never do that again(!) and instead find a programmatic way of doing it!), and I was looking for a way of writing librarian software for the EX5 for several platforms, as I noted that a lot of people on the EX5 forums were using Apple Macs (No! Let’s not start a platform war! ) so I wanted a way of targeting several platforms with little effort. I also noted that that a lot of EX5 owners also religiously clung onto their SY77/SY99 synths as well, but that is another story!
After looking at C/C++ and cross platform GUI toolkit libraries (none free at the time that I could find that were useable), I looked at Java (after buying a book in PC World to do some research) and after some experimentation decided it would be the hardware independent platform of the future for me: A language that would run on any Platform with a Java compiler and run time.
Back in those days I was using PC wanting to target OS X. Now (after borrowing a MAC in 2007 for compatibility tests, and loving the experience so much I did not want to give it back!) I write on OS X targeting PCs!
So far it has worked a treat. It might not be as efficient as native code, but you would be hard pushed to notice that these days (as somebody who used to hand code in assembler, optimising code for floating point and integer units working in parallel, keeping variables in registers, etc. for performance, I don’t) as the “hot spot, just in time” byte code compilers are very good. You might not want to write a performance demanding program like Cantabile in it, but for general computing it is (IMO) the dogs whotsits.
Today I have a suite of librarians for my synths (well the ones where I am not happy with the offered librarians) that run on Windows, OS X and Linux, with the occasional report of other platforms such as Solaris (if it still exists), all with very little effort to achieve that. Just stupid things to be aware of, like mouse button events (button press on one platform, button release on another; ALT modifier on PC, CMD on OS X……).
And with Java you can hit the hardware or OS specific aspects if you need to via “Java Native Interface”. For example, Java MIDI SYSEX support is totally broken on OS X (it used to be on PC as well but that was fixed on PC circa 2005!), but I have written a “Service Provider Interface” (in C, which is so old fashioned……) that provides an interface to Apple Core MIDI services, and I have written that so it is transparent on PC and Linux, but does what it needs to on OS X.
So it really works for me.
Back OT (after a long ramble - quaffing some nice Aussie wine whilst away on business on my own in a random hotel!) I am following Brad’s updates on his GUI toolkit with interest and keen to see where that leads to Cantabile wise. Obviously with the music scene being dead for the past 18 months, I have had little need for this amazing live host, but will be keen to start getting back out there as things open up again - before I get too old for this gigging malarkey!
Sometimes this is true, but usually more with libraries than languages. If you look at a modern language like C# most of the language features come from computer science and not business marketing. Some of these concepts sound daunting, but they’re there for a reason and are designed to make things easier… but they require some work to understand.
If that’s the case I suspect you’re probably not using the language as intended. Lots of modern language concepts are designed to make the code more manageable, more concise, more independent, more clearly defined.
That doesn’t surprise me at all. C++ is complicated language with a complicated toolchain and build environment. Throw in a complex library like Juce, with it’s own build requirements and it’s fragile environment that’ll bite you any chance it gets. If you’re not familiar with C++, then this is fraught way to learn it and definitely not the way to learn OO concepts. I used to love C++, now I almost hate it.
If you want to learn OO, I’d recommend C# or like @Derek suggested Java. They’re similar in many respects, but personally I prefer C#.
Here’s how easy it is to get started with C#… download and install the SDK, open a command prompt and type:
> mkdir MyProject > cd MyProject > dotnet new console > dotnet run
For code editing probably the easiest is Visual Studio. Install the free community edition and then type
start MyProject.csproj in the MyProject directory.
(If VS is too heavy for your liking, try VS Code with the C# extension - super lightweight, cross platform development environment but a little trickier to setup for debugging etc…)
From there I’d pick a couple of really simple concepts and have a play around. Start with some simple procedural stuff (
Console.WriteLine. From there try a simple
class with some methods and properties.
If you want some simple C# code to look at, try this article of mine. It covers writing a simple math expression engine. Perhaps take a look at the
Tokenizer class for a really simple example… and happy to answer questions if you have any.
@Derek, I totally understand why Java suited your needs - particularly for cross platform UI and I probably would have chosen it back in the day too for projects like you’ve described. But C# is an incredibly elegant language and it’s getting better all the time.
- Property accessors are better than get_Property()/set_Property()
- Generics are a feature of the runtime type system, not just syntactic sugar
- LINQ makes for extremely concise code when working with collections
- Dynamically generated methods - generate code at runtime that basically compiles to machine code.
- Unsafe mode… descend into unsafe memory and pointers when needed
- Open source and cross platform
- The native interop is unbeatable
That last point about interop always amazes me. You mentioned JNI where you write C code that’s accessible from Java. In C#, you don’t need the C code - just call external dll/so as required. The main thing it can’t do is call C++ code easily. In fact the interop is so good, GuiKit is written entirely in C# but on Windows it talks to hundreds of Win32 API functions directly and on OSX it uses the Objective-C runtime directly. No supporting dll/so required.
I’ve done the dotnet stuff above. I don’t really know what I’ve done, but it seems to have worked and I got the ‘Hello World’.
And I’ve managed to find the code in VS, though it wasn’t obvious how to proceed.
It’s daunting, and I’m still licking my wounds from last time, but I’ll give it a go, at least to grasp the basics. How I get from here to creating a VST plug-in I have no idea. At some stage I’ll trawl YouTube for a C#/VST tutorial.
Maybe I’m too battle-scarred to go further, but I appreciate the steer.
I was suggesting C# more as a way to ease into the OO programming.
For VST you probably need C++ although there is this but I’ve not used it so can’t comment on it.
Time for me beat a strategic retreat, methinks. I don’t even have a starting point for what any of that means.
I’ll stick with C++ on the Arduino (I’ve about completed my current project, which I intend to show here at some point - it works beautifully with Cantabile!) and I’ll save any ambition to build a VST for the next lockdown…
I very much appreciate the advice. You’re busy enough without me interrupting!
@brad I think C# was just emerging in .net when I looked at this in 2000. Java has indeed worked well for and my investment in it is too heavy to change now, but I probably need to look at C# as well some time. Certainly works well from a Cantabile user perspective!
He hacked our brains, we’ve had his collections laying about the house for years.
… unhealthy obsession with brackets! I’ll get some obscure error and all it will mean is that I have a curly bracket missing somewhere completely unrelated to the error
Do you mean a little like missing a full stop in a COBOL program? How many compiler errors from just one missing full stop?!
Coming from an I.T. background (Before I retired from it), I was an Assembler, COBOL, PL/x, Whatever-needed-doing-that-day Language man. I also needed to learn C/C++ due to the lecturing I also did. The transition from procedural to OOP languages was not an easy one for me. However, I kept hammering away from it until it suddenly seemed to fall into place.
I still tinker, mostly with TypeScript now, but recently had a need to do some C++ only to discover a hole in my brain where all that stuff used to be stored! So, I did a refresher course, and I can highly recommend this one: https://www.udemy.com/course/the-complete-cpp-developer-course.
I got it during one of udemys many sales, and if you keep an eye on the course, it will at some point drop down to the £9.99 I paid for it. Covers everything you need and more.
Once it clicks with you, it will feel nonsensical to code in any other way.
Enjoy and good luck with it all.
I hear what you’re saying about the full stop, but I seriously think that OO languages really do over-play the brackets. The source code would be half the size without them, and they add nothing that an indent couldn’t achieve much more cleanly.
I know I’m railing against something that’s set in stone now, but to my way of thinking programming languages should be MORE readable since the 1960s and 70s, yet they are actually LESS!
I feel your pain, man. If I had spent my 39 years learning how to make money instead of learning how to make machines work, I would be filthy rich today.
COBOL and C are perfect for control freaks like me. Object Oriented programs require you to take a leap of faith when using somebody else’s libraries. Good luck with that!
I think I once had 2000+ errors from a single wrong indent in PLM/2 (Intel’s microprocessor high level language)
Yeah, but you can see curly braces and you can’t see white space and when you throw in spaces vs tabs, tab sizes there’s a new set of problems. I know Python and makefiles use indents, but I prefer the braces.
fwiw, Microsoft is making a concerted effort to reduce the over head in C# like getting rid of the need for braces around name spaces, global usings, top-level statements and what they call “cleaning up horizontal waste”. They’re doing this to reduce friction for new devs.
In C# 10, this is a complete program:
I’m with you on the curly brace thing.
I’m with Microsoft - that looks MUCH better.
No need for those brackets around the quote marks, and time to get rid of the semi-colons (just put each command on a new line), then we’re on a roll!
Wouldn’t that then imply this is valid:
var input = Console.ReadInput "Enter Something:"
in which case, what does this mean:
var input = Console.ReadInput "Enter Something:" + 23
Does it mean to prompt with “Enter Something: 23”, or does it mean to prompt with “Enter Something:” and then add 23 to whatever they entered?
To clarify it, you need to do this and you’re back where you started.
var input = Console.ReadInput("Enter Something:") + 23
Or, you need to do this and you’re now typing more than before.
var input = Console.ReadInput "Enter Something:" input = input + 23
Making the parens optional introduces two problems:
- The code becomes ambiguous
- Makes the language inconsistent with two ways to invoke a function.
Another good reason for semicolons is it makes error recovery more accurate because the compiler has waypoints in the code where it can re-sync after a syntax error - meaning you get more meaningful/accurate errors.
I’m not saying it couldn’t have be done, but these things are deliberately chosen because there are advantage in doing so - mostly for consistency and removing ambiguity. C# is very big on this consistency thing and will actually give errors if you put semicolons where they’re otherwise redundant (unlike C++). I like this kind of precision.