Tips for coming from an ActionScript background

I’ve been an ActionScript developer for the past five years and I’m finally moving into other languages and platforms. I’ve got plenty of experience with OOP and know all about design patterns 'n such. The hardest thing for me to grasp with C++ and openFrameworks right now is how to structure my files and code in my project. I really don’t know anything about best practices when it comes to C++ dev. I was hoping there would be some people on the forum that have ActionScript experience and might have some pointers on how to organize things. Naturally I’m quite accustomed to the reverse domain package structures 'n such but I haven’t come across anything like that when it comes to structuring C++ code. I’m a little familiar with namespaces, but they seem to be avoided throughout openFrameworks. At any rate, general tips from an ActionScript perspective would be awesome.


hi matt,

how to structure things is really up to you. C++ is an old language which means there are many ideas about what best practices might be. if it’s practical for a project, you can do everything in the testApp.cpp/.h (although this isn’t recommended if you have more than a few hundred lines of code).

when i’m working i like to make classes for each of the building-blocks of my app, and try to keep each .cpp/.h file pair as small as possible - rule of thumb for me is, if a .cpp file is more than 500 lines it is a candidate to be split up into smaller components.

namespaces in C++ are very large-grained things. you would wrap an entire library in a namespace, for example. on the finer-grained level classes take care of wrapping things up.

hope this helps a little.

It’s common to arrange classes in subfolders for larger projects - e.g. “client”, “server” (adapt makefiles!).
I’ve seen namespaces used on a fine-grained level and they can help to keep things organized if you have a big project evolving and changing over time - it’s probably largely a matter of personal preferences.

Thanks guys.

I too am coming from actionscript and can’t get my head around one thing: are there event listeners in openframeworks (or c++ in general for that matter) at all? Did a lot of research but doing something simple like adding a mouseclick listener on an object seems non existant…

Hey Noktai, take a look at ofxMSAInteractiveObject. It’s pretty self contained and similar to Actionscript events…-veObject.h