General Question Lua or C++ for newbie developer?

Marijn

Active member
Joined
Mar 5, 2008
Messages
755
Reaction score
168
Points
43
Location
Amsterdam
For some two years I've been playing with Orbiter and I'd like to make a start developing add-ons. To get myself started, I've been browsing this forum and the various documentation as provided. I am interested in creating MFD's for navigational purposes and glide planning/optimization.

To me it seems that there are two distinct ways to go: either using Visual Studio creating dll's or using the Lua script MFD. Since both programming environments are new to me I like to make a wise decision on which of these to concentrate my efforts. I am not aware of any pro's and cons of using these programming languages. Are all Orbiter API functions available in both environments? Any suggestions are greatly appreciated.
 
For some two years I've been playing with Orbiter and I'd like to make a start developing add-ons. To get myself started, I've been browsing this forum and the various documentation as provided. I am interested in creating MFD's for navigational purposes and glide planning/optimization.

To me it seems that there are two distinct ways to go: either using Visual Studio creating dll's or using the Lua script MFD. Since both programming environments are new to me I like to make a wise decision on which of these to concentrate my efforts. I am not aware of any pro's and cons of using these programming languages. Are all Orbiter API functions available in both environments? Any suggestions are greatly appreciated.

I would personally prefer C++ over Lua. If you used Garrys mod for example, Lua would be right for you. I recommend C++ because it has more power over a lot of variables. The other benefit with C++ is that you can use it in other application development. :thumbup:
 
If both is new to you, start by C++ and then go to Lua. While Lua is the simpler language, because it swallows almost everything you throw at it, C++ constant nagging at you helps you learn programming, which is independent of the programming language that you use. Just learn first to treat even compiler warnings as errors that need fixing. And especially the fact that C++ complains if a variable has another type as you expected can be worth a lot of time compared to Lua, which would just silently try to do the best with the variable.

Next, a MFD is maybe the best place to start coding for Orbiter, but Lua isn't the best tool then.

What you need to learn for Orbiter, what no beginners programming book can teach you, is writing fast code. Fast is not short code, fast is not always looking elegant. There are some pretty patterns around in the real world, which are better than the most direct way. Especially for MFDs, which can have a strong effect on frame rate, if done bad.

Essentially all work in Orbiter is purest game programming, if you can happily code for Orbiter, you are ready for writing your own games as well.
 
Last edited:
I agree. For now, C++ is more convenient. That could change in the future, though.
 
No, NO! C++ is horrible for a beginner. Go with Lua instead.

The reason for this is that you will be forced to take care of things you aren't yet prepared to. It's not about laziness, it's about frustration and usefulness. After you get experience on how things work on the surface, you may then want to venture under the hood, and when you do, it'll be way easier than if you had jumped to C/C++ right away.

Most current programming languages are based on common elements, and when you've mastered, or gained experience on how one specific programming languages does (or rather, implements) a specific feature, it'll be much easier and hassle-free to explore other options. Actually, a programmer, specially on the professional field, is expected to quickly grasp new technologies, including new languages. Don't do the complicated thing first, but build up your skills.

Don't believe on the 'Learn C++, because it's useful', because it actually means 'Learn C++, because it's useful to the experienced'. It's not a flaw, but actually a feature. It's how the language was designed, and it's why you shouldn't expose yourself to it right-away.

One last tip: don't follow formulas and catchy words, unless you understand them. Be it agile, oop, functional, elegant, test-driven. Each and every one has it's flaws and virtues.
 
No, NO! C++ is horrible for a beginner. Go with Lua instead.


C++ is more difficult to grasp then LUA, but once you do, it leaves you with a much more powerful tool. I'd go with C++ over Lua as well.

A good tutorial:
http://www.cplusplus.com/doc/tutorial/

Don't forget to read the API_Guide.pdf to get an idea of how to write for Orbiter, here's a tutorial on how to set up your compiler: http://www.orbiterwiki.org/wiki/Free_Compiler_Setup (just use VC2010 over VC2008) and remember that the API_Reference.pdf contains description of every class, function, struct,... that a user can call :)
 
Based only on techincal merit Lua would be the clear winner, primarily because it's designed to embedded into things like Orbiter. However, there are a couple Orbiter-specific gotchas.

First, Lua support is apparantly new and there are problems with scripted mfds in P1 which are reportedly fixed in recent betas. That would put you in the difficult spot of developing in a new language inside a beta environment which is also a new lanugague. Ugh.

Second, while performance shouldn't be your first, second, or third consideration a little long-term planning never hurt. I'm fairly sure that Orbiter starts a new interpreter for every mfd instance. I know it does for scripted vessels. That's a significant amount of overhead which can't be profiled away.

Although it sounds like C++ is a clear winner, I'd include a warning that it's hardly a good first language for anything or anyone. I wouldn't really say the Orbiter SDK is the pinnacle of object-oriented design either. So, basically my $0.02 would be:

1. If you have a decent background in software development, C++ wins right now. (Though in this case "learning Lua" would take about fifteen minutes.)

2. If you never, ever wrote anything before then Lua. The benefits of a scripted environment will grossly outway any minor aggravations. Honestly, if you come up with something super-awesome and need to port it to C++ for performace reasons it isn't the end of the world.

3. If you're somewhere in the middle, eg. you wrote a couple of lousy pieces of software or something. C++ for now, Lua in the future. C++ is more convient right now, and it's certainly possible to do horrible things in any language.
 
No, NO! C++ is horrible for a beginner. Go with Lua instead.

What do you intend to teach him that way? That is like saying "Driving a car is horrible for a beginner, I can teach you to call a taxi". Because that is essentially what you do with Lua. Lua is a language to interact with C99/C++ modules. You can only do as much, as the C++ programmer of the hosting application permits. And Lua makes you feel this.

I would be the last to complain about Lua, it is my favorite embedded script language, but it is not more than that. A small compact language, that is quite capable even of complex scripts, but still, it is not made to develop complete application, but to extend existing applications.

The reason for this is that you will be forced to take care of things you aren't yet prepared to. It's not about laziness, it's about frustration and usefulness. After you get experience on how things work on the surface, you may then want to venture under the hood, and when you do, it'll be way easier than if you had jumped to C/C++ right away.

So he will NEVER be prepared for them at all? Great teacher. A child will never learn to swim, if you always tell it that it is not prepared for swimming yet and should stay in the one-foot-deep pool for toddlers. You need to make it swim when it is still easy to abort the attempt, and then encourage it to swim longer, and into the deeper water, if it is prepared enough. The trick is to start swimming at all and then keep on trying it.

Most current programming languages are based on common elements, and when you've mastered, or gained experience on how one specific programming languages does (or rather, implements) a specific feature, it'll be much easier and hassle-free to explore other options. Actually, a programmer, specially on the professional field, is expected to quickly grasp new technologies, including new languages. Don't do the complicated thing first, but build up your skills.

True and wrong. While there are many common elements in a family of programming languages, there are many different families. Lua is similar to C++ because both use structured programming as core doctrine, but both are so different that you start again at a new language, even if you mastered already the other.

C++ is a compiled object-oriented programming language. Lua is an embedded imperative-functional script language. Two different worlds.

Don't believe on the 'Learn C++, because it's useful', because it actually means 'Learn C++, because it's useful to the experienced'. It's not a flaw, but actually a feature. It's how the language was designed, and it's why you shouldn't expose yourself to it right-away.

I have never read such a huge pile of rubbish about C++. C++ is not for the experienced. Assembler is. Brainf...k is. I would even say that Clojure is. Because all such languages require you to think more than just around one corner for explaining a computer what to do. But C++ is not more useful as any other full programming language. It is a tool. Not more.

But there is something that you need to know about tools: You can use a stone for hammering a nail into the wall. But a hammer can do that better, so if you have access to one, use it. And learning to properly use a hammer as soon as possible in your life pays out quickly, because the simple primitive hammer that you have at home is actually the result of 2500 years of technological evolution and experience - a good hammer is a high tech product. The hammer will always be better than the stone, and even more so in the hands of somebody experienced.

Lua is the stone. It is primitive enough to be used everywhere for everything, but it can't do anything good and relies on the existence of proper tools to achieve any effect. Without installing a C++ library, Lua can't even do basic file system operations (Lua + Penlight + LFS on the other hand is something that you will never want to miss again). C++ is the hammer. You need to think a tiny bit more for putting a nail in the wall (eg, choose the best side of the hammer), but then it does it much better and faster than the stone could ever do, and does not exhaust you as quickly. You can put a picture on the wall with the stone, but with the hammer, you can build the house in which you want to hang the picture on the wall.

C++ is a very explicit language. It does almost nothing, that you did not tell it. There are no secret hidden surprises, like you can have for example in Lua (Just throw a table into a function that expects a string - if the programmer of the function was smart, something happens. if he was not, the program crashes silently.).

The problem what many people have with C++: It does always do what you tell it. It does not treat you like a child, going on like "That makes no sense, maybe he actually meant to do that. I'll fix it without telling him." It will try to do what you tell him, and if it can't do that, it will tell you that so often that you can get frustrated, if you never learned the true first rule of C++ coding: If you fail to solve a compiler error, ask a more experienced programmer for help. C++ is nothing for people who think they are smarter than them all. C++ teaches you programming in the real sense of it. It teaches you to solve problems before you program them.

Of course you need to learn concepts for C++. Like the data types. Or basic historic program patterns, that come from having evolved in primordial times of computing. Luckily, because C++ evolved from C, which was intended to be actually a very simple high-level language that is still so close to the hardware that you can use it without a huge operating system around it. It has only very few rules, just like chess. You can use goto in C++, but there are better statements in it, that do the job and tell other programmers what you intended with the statement.

It is not better for the experienced. That is actually the biggest misunderstanding that you have about C++. C++ permits you to program already great programs with medium skills. It gives you a harder start, because you need to know a bit more before you can write even a simple Hello-World-Program, but then, every new lesson you learn brings you quickly closer to greatness.

If you are really experienced with C++, you can do stuff, that only few other programming languages can. And you only can get that experienced, by programming in C++. If you tell people to give up C++, because the first steps are the hardest, you are doing them a bad service. because the first steps in any programming language are hard, and for some languages, the steps remain hard. Not so for C++. After you survived the first traps, the only enemy for you is yourself. Because C++ does what you tell it. It even crashes right in front your face, like a good loyal dog, if you tell it to do that.

And I won't lie there: C++ requires you to really think about what you want to do. Lua doesn't care what type a variable has. You can turn a number into a string and back, and your program will crash on runtime, if you don't watch for it. C++ will complain already before you can run the program. And it will not be very diplomatic then. That is the price.

I would even go so far to claim, that Lua can never teach you programming. Because all that aspects, that really define programming, the art of formulating problem solutions in a way that a computer understands them, are not taught by it. It teaches you only to do Lua. You can do great things with Lua, if you understood it, and if you really learned programming somewhere else, learning the dark magic of Lua is much easier because Lua does not know stuff that complete programming languages don't have.

C++ is not about knowing how to program with a pointer to a pointer to a pointer to a pointer to a pointer to a pointer to a pointer to an int that you can use as index for accessing an array of characters that is defined by a pointer that is located at the target of a pointer, etc. That is sometimes needed if you program C++ on a small embedded device, like the controller of a car engine - but only very few C++ programmers ever get good enough for solving their problems that way without punishment.

It is the extreme example that brings the language in discredit, because it does not give you limits on what your program can do - the only limit is the hardware that has to run the program.

But in reality, in 99% of all cases, good C++ coding will be about preventing such language constructs to ever happen to you, or your unlucky successor who has to deal with your program code. And C++ lets you do that as well. You can write great software interfaces that any beginner can use - and luckily, martins was closer to this kind of C++ when he did the Orbiter API.

Programming C++ programs for Orbiter is much easier, than for example making the same with for example just Windows. Even with wxWidgets or MFC, making a simple windows application is about 20 times harder than making a orbiter module.

So, in that sense, it is even easier to learn C++ with Orbiter, than anywhere else, including Linux/UNIX.

One last tip: don't follow formulas and catchy words, unless you understand them. Be it agile, oop, functional, elegant, test-driven. Each and every one has it's flaws and virtues.

Never do anything if you don't understand it. Should be the first rule of survival, but you make it sound like you can actually get old without ever learning it. "Uh, what happens if I stick this needle into this tiny hole in the wall?" is a good start of curiosity, but usually also the end of it.

The same applies to C++ - if you don't understand it, don't talk about it.

Stand back in awe and watch us move code.

Or ask us a question and don't be afraid that we might give you the answer in return. I have never met a C++ programmer yet, who was really reluctant to help somebody who wants to learn C++. You have not really understood something, if you can't teach it somebody else.
 
For some two years I've been playing with Orbiter and I'd like to make a start developing add-ons. To get myself started, I've been browsing this forum and the various documentation as provided. I am interested in creating MFD's for navigational purposes and glide planning/optimization.

To me it seems that there are two distinct ways to go: either using Visual Studio creating dll's or using the Lua script MFD. Since both programming environments are new to me I like to make a wise decision on which of these to concentrate my efforts. I am not aware of any pro's and cons of using these programming languages. Are all Orbiter API functions available in both environments? Any suggestions are greatly appreciated.


So, Marijn, did you know beforehand that this was a subject that would be met here with as much feeling and, er, "belief in the one true way" as most people would only devote to a religious or political issue?

But I'm glad you asked, as I am in the same boat as you as far as interest in programming for Orbiter. I'm following the debate with interest.

But I don't think I'll ever admit which way I go, to avoid offending the fervent...
 
Urwumpe, pardon me for not replying on your level, with a comparable well-written post. No sarcasm intended, but I prefer not to romanticize choices. And my English is not that good.

We could argue on your choices of metaphors (while you say 'driving a car' and 'calling a cab', I'd say 'learning to assemble and drive' and 'learning to drive'), but I rather not. Metaphors have limits on precision, which is, by comparing our wording choices, very low.

Now, Lua is an interpreted language mainly used for scripting, which doesn't mean it's incapable of standing alone. It does have an I/O library, a standalone interpreter and REPL, useful modules, garbage-collection, and a generally hassle-free syntax. I see it as superior for the beginner in comparison to C++ because it allows for a less constrained programming, quick testing and no need for manual memory management (as even smart pointers and garbage-collected C++ have crude pitfalls for the non-initiated). Plus, with the Lua console, debugging is easier when developing for Orbiter.

As for the statically-typed vs dynamically-typed debate, I prefer to simply say nothing about it, as any general answer would be indoctrination.

Moving on to the 'language barrier'. If the OP was comparing Haskell and Assembly, I'd say you're right: if you pardon this metaphor, it's like learning English and then Chinese. But he is not. Even with different syntax, both are imperative, have lexical scoping, include common control structures like branches and loops, functions, useful libraries and comparable data types and operations on them.

After rereading your post (and ignoring some constructs with latin names, such as reductio ad absurdum, ad hominem and ad nauseam, which remembers me of an old thread), the central point seems to be about how similar should be the entry barrier to an idealized state (that is, using mostly C++). Well, you don't start driving on the road with traffic, do you? Just because you started driving by taking your mother's car out of the garage, it doesn't mean you'll NEVER drive on a freeway.
 
Now, Lua is an interpreted language mainly used for scripting, which doesn't mean it's incapable of standing alone. It does have an I/O library, a standalone interpreter and REPL, useful modules, garbage-collection, and a generally hassle-free syntax. I see it as superior for the beginner in comparison to C++ because it allows for a less constrained programming, quick testing and no need for manual memory management (as even smart pointers and garbage-collected C++ have crude pitfalls for the non-initiated). Plus, with the Lua console, debugging is easier when developing for Orbiter.

I see it is deeply inferior because of exactly that. It is intentionally so flexible and carefree, that it leaves you guessing more, what error you just programmed. Also, you can hardly be less constrained than in C++. Lua only allows you, what you have C modules for.

And unless you tried to implement your own iterator for a task you have pretty much no clue how terribly complicated Lua can get on itself (Requires knowledge of how to implement closures in Lua). And you will need it. Lua math functions are also not its strong side, Lua 5.1 doesn't even reach the accuracy of 32 bit floats. Things are converted a bit too often there it seems. Can be pretty annoying for Orbiter, if you try to use the Lua alone for something without being aware of the numerical limitations.

Again: If you don't know what Lua is, it will disappoint you. And that even more annoying than C++. I can just recommend you to try a few matrix multiplications in Lua in a row. If you do the same in C++, the error is somewhere in the 9th digit after a about 10 repetitions. In Lua, you have already errors at the 5th digit after 3 multiplications. if you don't know this, you won't be able to tell at a point, why your program fails.

Another annoying behavior awaits you in the cosine function - it is defined by the sine function in a very approximate way, resulting in pretty large errors - cosine 0 is not 1, but 0.9995.

It is a simple scripting language for enhancing programs. It is not intended for much more. Even if you can use it like that - it is maybe better than other scripting languages there, but not at all comparable in all aspects that you need for Orbiter for the tasks that the OP intended.

We used Lua for controlling measurement robots. Works well, if you are aware of its limitations. We needed to implement all critical functions in C (well, actually Labview) and let Lua only command the next step of a measurement. It was accurate enough for setting frames, but required special care for making the math avoid numerical problems early.

Well, you don't start driving on the road with traffic, do you? Just because you started driving by taking your mother's car out of the garage, it doesn't mean you'll NEVER drive on a freeway.

I don't know how you do it in Brazil, maybe you have a few hours of simulator training in advance, but here you do directly start in the traffic. With a driving instructor, but otherwise with everything that nature and mankind throw at you (one of my first lessons had a monsoon like rain shower at rush hour). If you have your lesson during rush hour, this means learning the chaos directly, maybe on your first drive. By the time they let you in car, you are knowing the rules already, now comes the situation awareness and feeling for the car.

The rest of your strong words had been cut out and put into the toxic waste bin, I am sure they are not meant for being recycled in this post.
 
Last edited:
Thanks very much for all the well argumented replies so far. It will certainly aid my decisionmaking. Of course these kind of x vs. y threads stir things up a bit. I am happy to see that both LUA and C++ have enthusiastic supporters within the Orbiter world.
 
Although I REALLY don't want to put myself into an x vs y argument (since I don't have the knowledge to argue in depth about either x or y) I thought I would just give my opinions coming from personal experience...

I think LUA is better if you have had some (but not alot) experience writing code. Also I think this has been said so I will not labour the point too much.

It really depends on your own requirements/abilities/time available. If you have an idea in your head of how your program/code will work then LUA can be better to read and type since it reads a bit more like a real life conversation than an equivalent piece of C++ code (again just my personal observation).

Undoubtedly C++ is better for a multitude of reasons, if you can manage it. But I think LUA can provide you with an end result much quicker from a standing start than going through and learning the equivalent C++.

Also another thing to consider is that you will probably get more support from this forum for C++ issues as there are some pretty clever people on here with it...

So that's the way I see it, whether I'm right or wrong depends on you and your opinion. I'm starting to try making script mfd's with LUA and the documentation is there but not as extensive as for C++.

Good luck and I hope you succeed whichever way you choose to go!
 
Back
Top