5 ms·
I keep on thinking I want to pick up C again (made a living with it 20 years ago), then I remember all the goodness that C++ adds (made a living with it 10 year
by antidoh 14y ago
I keep on thinking I want to pick up C again (made a living with it 20 years ago), then I remember all the goodness that C++ adds (made a living with it 10 years ago), then I remember that C++ is huge and cryptic and I get all depressed again.
- primitur 14y agoLearn Lua. I went through the same basic phase as you described, and once I'd gotten my competence with implementing Lua bindings up and running, I never looked back. For me, Lua+C is the most elegant combination of language tools I've used, and as a developer with 30+ years of experience, I've used most of them. Lua really, really rocks - especially if you look at it as the domain tool it is, and not the prepackaged broad-spectrum scripting language that many people consider it to be ..
- qznc 14y agoWhat do you use for basic data structures in C? Stuff like hash map, priority queue, sorted set, etc.
- anonymous 14y agoWhen you're using C as a layer under some other high-level language you get those implemented for you. For instance, if you write Python bindings, you will use Python's data structures from C. If those are too slow for you, you'll want a specialised structure - there are many libraries providing collections for C.
- zem 14y agoglib is not bad. you can even use vala, which is c-like, but has built in glib and gobject support.
- primitur 14y agoFortunately, it is very easy to implement these structures in Lua, if they haven't already. The basic datatype of Lua - the table - can be treated as a hash map, a sorted set, a priority queue, very, very easily .. in fact if you think these things need to be implemented in C, you're missing a big part of the picture with Lua. The power of Lua as a language is really derived from the "morphological" nature of the basic table datatype .. Lua has all of the structures you're asking about, already. And anything it doesn't have, which one would truly need to derive from the C/C++ side, is a few simple binding calls away .. but anyway, tables will do all you ask, and more, if you learn to use them properly.
- mikec3k 14y agoAgreed. At my last job I did most of my programming in Lua. We used C++ & Cocos2d-x with LuaC bindings for our game engine and wrote all of the game logic in Lua. I really like a lot of Lua's features, especially closures and the way metatables work. Although Lua doesn't support true classes, it's possible to implement them nicely through metatables.
- charlieflowers 14y agoWhat do you mean by "...as the domain tool it is, and not the prepackaged broad-spectrum scripting language..."? I haven't used Lua yet, but reading about it led me to believe it was a "broad-spectrum scripting language". I'd like to understand the distinction you're making more deeply.
- wtracy 14y agoIt doesn't have the "batteries included" philosophy of languages like Python, where there's already a ready-to-use library for everything. If you want to do anything non-trivial with Lua, you'll probably have to touch some C code.
- _dps 14y agoThere are two ways to look at Lua. There's Lua-the-abstract-language which can certainly be used as a broad-spectrum scripting language. I certainly use it in that capacity. Then there's Lua-the-implementation(s) (PUC + LuaJIT), both of which are designed from the start to be maximally easy to embed in a host C program, or to delegate work to shared libraries written in C. In my opinion, it is an order of magnitude better at this than Python or Ruby; some of this is a matter of taste but I believe most of the advantages are objective. Not to put words in the GP's mouth, but I take the "domain tool" comment to mean: "You really should try to use this in close cooperation with C, and not just as a stand-alone language. If you don't you'll miss a significant portion of the value." Note that using it in concert with C need not be done in a single person's head (though this case is also common); Lua+C is an extremely productive way for a systems programmer and an applications programmer to work in harmony while enjoying most of the best of both worlds.
- primitur 14y agoYou got my message pretty well 100%, I was just about to type a sentence very close to this one: "You really should try to use this in close cooperation with C, and not just as a stand-alone language. If you don't you'll miss a significant portion of the value." Yes, you can just run 'lua' at the console and treat it as a local scripting language, with the default bindings available in the distribution Lua-interpreter .. but you can also take the VM itself, make it your own, and put it in your own project for domain-specific applications. For a great example, take a look at MOAI: http://getmoai.com/ http://getmoai.com/ Essentially, MOAI is a collection of C and C++ libraries, tied together into the Lua VM to provide a cross-platform development tool for Android/iOS/Linux/Mac/Windows/&etc. This is accomplished by 'gluing' the Lua VM into the space between a variety of different API's and making those API's available within the Lua environment - in this capacity, it serves very, very well. I could imagine building an entire GUI/OS in a very similar way, and may end up doing just that one day soon ..