Temple of The Roguelike Forums
Development => Programming => Topic started by: Krice on May 25, 2013, 12:04:25 PM
-
I think it could be nice to program some other language than C++, as a "hobby". I'm thinking of something different than object-oriented that would be also suitable for large scale programming. Any ideas?
-
Go looks very cool.
A non-OO take on interface and composition
Concurrency facilities built into the language
http://golang.org/
I played with it a while when it came out. That was like 3 years ago, it's seen adoption in server areas, I was always curious if it'd get enough graphical support to do a game in.
-
Clojure is interesting language that runs on multiple platforms. It is functional language with access to object oriented constructs. One can definitely write a game with it and there's even roguelike tutorial available for it (if you want to do a roguelike). It is suitable for large scale programming. Another interesting option is Scala + Akka.
-
Ocaml, definitely (limited to its purely functional features). It's good for large projects, and will teach you a lot of new things if you haven't tried functional programming yet. It will make you a much better C++ programmer too, BTW.
-
What I hate in most of those other languages is the syntax, like:
a[q->q 2 : 44,a, --c)
How can you read or write code like that?
Maybe I should just concentrate on strict modular type programming in C++ to avoid some of those regular problems like over-sized level class (and some other classes).
-
Your code snippet looks almost like the new lambda syntax in C++ ;D
-
Javascript is not too horrible if you're used to a C style syntax. There are a couple of offerings that will give you native code via a JIT that are not too shoddy performance wise as well.
-
The most obvious is C, but I'm pretty sure you want something aside from that so...
A lot of people I know use Python as a hobby. I think it's OO, but I keep hearing good things about it. It seems like every new coder who I meet who learned how to code recently codes in python. Seems to be enjoying some popularity right now.
JavaScript is okay, although it really, really makes me angry with some of the features it lacks (File IO for example). But it's pretty straight forward and simple.
You could learn ASM for a classic system like the NES, Atari, or C64 or something, but that probably wouldn't count as a hobby with how much work it would be.
There's the various Linux shell scripting languages. They can do some pretty cool stuff.
If you wanted to go old school, you could learn pascal.
-
"JavaScript is okay, although it really, really makes me angry with some of the features it lacks (File IO for example)."
This is not a problem if you use one of the javascripts designed to be extended/embedded , such as V8 or Spidermonkey. They're designed to be extended with C/C++.
I've used them to provide scripting for large scale C++ applications, for example.
-
What I hate in most of those other languages is the syntax, like:
a[q->q 2 : 44,a, --c)
How can you read or write code like that?
Maybe I should just concentrate on strict modular type programming in C++ to avoid some of those regular problems like over-sized level class (and some other classes).
You should try APL then ;D
Anyway, different languages look different. If one has been programming with LISP only then Python will look like a horrible mess. I remember when I switched from Basic to Pascal and was wondering how the computer can execute the program when there are no line numbers (that was like 25 years ago). It's a matter of what one has gotten used to.
Learning something like Java should be easy since you have been programming with C/C++, but will you learn new concepts like that? Of course you could learn Java + Akka and start writing distributed, concurrent and scalable applications though.
I'm trying to learn 3 different languages, one that is static and strongly typed (.Net), one that is dynamic and strongly typed (Python) and one that is functional (Clojure). They are different enough so that it's not just a matter of new syntax, but new concepts too. Learning C#, C/C++ and Java I wouldn't find that interesting.
-
I have some kind of strange problem with Java which makes me hate it. Besides I think it's too close to C++ anyway. I don't know, maybe I should just try to improve my skills in C++ while trying to finish my projects.
-
Java was designed for teams with dozens of low-quality programmers. It's a bunch of arbitrary jumps, loops, and doodads designed to ensure code consistency and readability. The result is a ridiculous amount of verbosity. It's also really not ideologically different from C++. Scala is based on the JVM but has meta-features that make it a lot more interesting.
-
You can try to actively use C++11 features. It's almost like learning new language :)
-
If you want my opinion about C++11 I think they ruined the language while trying to be modern. Programming languages are strange, because they are developed by non-humans (engineers and such).
-
If you want my opinion about C++11 I think they ruined the language while trying to be modern. Programming languages are strange, because they are developed by non-humans (engineers and such).
+1
-
Which features did you think ruined the language?
-
Haskell's a lot of fun, but there aren't a lot of libraries for game development. It was easy enough on linux, but getting the sdl and ncurses ports to work on windows is a pain. I've gotten a couple very simple roguelike demos done in haskell, though.
-
If you want my opinion about C++11 I think they ruined the language while trying to be modern. Programming languages are strange, because they are developed by non-humans (engineers and such).
I like the C++11 features. When I was learning C++ I would often google problems that had no satisfactory solution, such as
- Declaring and initialising a container object without adding elements individually or including a magic number
- Portable threading
- Passing functions as arguments without fiddling with function pointers, functors, etc.
- Prewritten and optimised random number generators with more useful distributions than a uniform spread over the range of a signed int
Often the "solution" would be to include Boost in the project, which was not a dependency I wanted. C++11 is gradually fixing these issues in a standardised way (and the sooner these features actually get implemented, the better).
-
If you want my opinion about C++11 I think they ruined the language while trying to be modern. Programming languages are strange, because they are developed by non-humans (engineers and such).
Hm. What exactly you don't like in C++11?
auto is awesome.
for(auto v:cnt) is beyond awesome.
initializer list is very very useful.
move semantics. well, it takes some time to fully understand it, but in the end it is powerful optimization feature.
variadic templates? hm. this one can blow unprepared mind away. and it takes significant amount of time and effort to fully comprehend it. but this is actually superior feature that allows some really advanced tricks.
the only feature that I think looks ugly is closures syntax.
this:
[](){}()
is now valid C++ statement.
but this ugly syntax is necessary evil, required to keep backward compatibility.
there aren't many punctuation combinations available in C++ to be used.
-
I'm completely satisfied with good old C++. There are some missing features, but they aren't all in all that important and most of them is coming with C++11 (which I don't use yet as my ancient hardware wouldn't stand new Visual Studio's demands for computational power). C++ is a terrible language for newcomers, but with years of experience typical problems disappear and you begin to actually like programming in C++. Of course, this happens to other languages, too, but I think it is not common for a programming language to take as long as 8 years to become proficient in (that was my case). I agree that it can be frustrating to find out that so many years of experience has not given such proficiency to you. Maybe I'm wrong, but I think this is the reason why you're looking for a "hobby" language.
-
Some new features that I like:
- lambda expressions, ever since I learnt functional programming, I missed them in C++
- initializer_lists, makes code much cleaner, and you can do some clever things with them
The big winner are range based loops, for me. I always hated typing in the traditional for loop, especially when iterating over containers. I used to use macros, like FOREACH(it, container) or FOR(var, from, to).
I actually use range based loops for normal integer loops now. Like so:
for (int i : Range(5, 10))
for (int i : All(container)) // iterates over the container, but you can use the index now
for (Vec2 v : Rectangle(10, 10, 20, 20)) // substitutes a double loop, Vec2 and Rectangle are helper classes that I use everywhere
-
- lambda expressions, ever since I learnt functional programming, I missed them in C++
I never learnt functional programming, but I'm missing lambdas anyway. Using STL is much harder without them (or, at least, much more awkward).
The big winner are range based loops, for me. I always hated typing in the traditional for loop, especially when iterating over containers. I used to use macros, like FOREACH(it, container) or FOR(var, from, to).
I hate typing loops, too, but there are better ways than macros to avoid it. I used to have a plugin for Visual Studio that would automatically complete the loop if you typed "for". You only needed to type a name for the counter variable and maximum value. There was also a special variant for iterating containers. Very good stuff, that plugin, but it wasn't free and generally plugins only work in commercial versions of VS, which is probably a big drawback. The other way is to avoid using loops at all. STL algorithms usually do a better job than any loop you could write explicitly. For some reason I dislike range-based loops - they are just syntax sugar that saves you some typing, they don't make you write better or even clearer code.
-
They do make you write better and clearer code, besides making your fingers less tired. The typical bug I always made was:
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++i) {
...
}
-
They do make you write better and clearer code, besides making your fingers less tired. The typical bug I always made was:
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++i) {
...
}
I once started to use 'k' for the inner loop and this bug has never happened to me again ;).
-
Hm. What exactly you don't like in C++11?
It's too not-C++.
And I don't know what lambda is.
-
I once started to use 'k' for the inner loop and this bug has never happened to me again ;).
Yes, use better variable names. Usually in loops like that you would use x,y coordinates so why not use them as variable names anyway? Or something that actually tells what those loops are for.
-
I'm completely satisfied with good old C++. There are some missing features, but they aren't all in all that important and most of them is coming with C++11 (which I don't use yet as my ancient hardware wouldn't stand new Visual Studio's demands for computational power). C++ is a terrible language for newcomers, but with years of experience typical problems disappear and you begin to actually like programming in C++. Of course, this happens to other languages, too, but I think it is not common for a programming language to take as long as 8 years to become proficient in (that was my case). I agree that it can be frustrating to find out that so many years of experience has not given such proficiency to you. Maybe I'm wrong, but I think this is the reason why you're looking for a "hobby" language.
Yea, no- It's just C++.
-
I will second Python. It's very easy to learn, quick to code, and has some interesting differences from other languages. I like that it requires precision but without a lot of extraneous typing (for example, the indentation of loops and other code blocks must be consistent, but you don't need lots of "{}" symbols that you'll lose track of). It's also the best interactive/scripting language I've seen in terms of running quickly and not blowing up your RAM. By using C++ libraries you can optimize the speed quite well.
-
I think Python is really beautiful language that is enjoyable to work with. Granted, it took me awhile to start appreciating the language; however, after that point was crossed there was no returning.
The biggest complaint I have about it is the slow migration from 2.x to 3.x. Progress is made on that every day though and I have managed to switch to 3.x completely, so I don't anticipate it taking forever.
-
Just FYI- Python really is a utility language. Good for hobby projects, but it has pretty low performance compared to something like lua, which is also elegant in very similar ways. Lua is also industry standard for games, so... I'd recommend checking it out.
-
Just FYI- Python really is a utility language. Good for hobby projects, but it has pretty low performance compared to something like lua, which is also elegant in very similar ways. Lua is also industry standard for games, so... I'd recommend checking it out.
Good for hobby projects like YouTube and EVE Online :P (sorry, couldn't resist)
-
Just FYI- Python really is a utility language. Good for hobby projects, but it has pretty low performance compared to something like lua, which is also elegant in very similar ways. Lua is also industry standard for games, so... I'd recommend checking it out.
Good for hobby projects like YouTube and EVE Online :P (sorry, couldn't resist)
It's a good point. Both of their code-bases were built before Lua became the informal standard.
-
I will second Python. It's very easy to learn, quick to code, and has some interesting differences from other languages. I like that it requires precision but without a lot of extraneous typing (for example, the indentation of loops and other code blocks must be consistent, but you don't need lots of "{}" symbols that you'll lose track of).
If compilation errors due to mismatched braces are your biggest problem, then of course, languages that don't have braces are an obvious choice.
-
As is a text editor that matches braces.
-
Just FYI- Python really is a utility language. Good for hobby projects, but it has pretty low performance compared to something like lua, which is also elegant in very similar ways. Lua is also industry standard for games, so... I'd recommend checking it out.
I find lua syntax ugly and way too verbose for a scripting language. And the language itself doesn't have some kind of standard 'ease of use' library. Each lua-based project invents it's own 'classes' and other infrastructure.
As for lua speed... Yes, in pure number crunching lua is good. But if you want to make some heavy computations, scripting language is hardly your choice. Other than calculations, when we use classes and other complex things, it's speed is more or less on par with python. lua's c/c++ interface is far from being convenient and far from being fast.
IMO lua is more suitable as some kind of macro/automation/plugin kind of language then something primary.
-
Hm. What exactly you don't like in C++11?
It's too not-C++.
And I don't know what lambda is.
Actually they are more closures then lambdas. And as far as I know, C++ is the only language
where you can control closed variables mode - by copy vs by reference.
And still. What features of new standard are making C++ into not-C++?
In any case, no one forces you to use features that you don't like for one reason or another.
-
No, they are lambdas. Closures (from named functions) have always been possible in C++ without extending the language.
-
Python can be it. I've been reading source code of Blender's python scripts and it doesn't look hopeless. It's quite easy to understand it without knowing a lot about the language.
-
No, they are lambdas. Closures (from named functions) have always been possible in C++ without extending the language.
Nope, they are closures, as they can close local variables:
int x=0;
std::vector<int> v;
fill(v);
std::for_each(v.begin(),v.end(),[&](int v){x+=v;});
Of course if they don't close any variables, they work as lambdas :)
Closures weren't possible in C++ prior to C++11 in any form.
Krice: python is a nice language to learn, yes. And it has vast number of libraries for most of your needs.
You can also peek at falcon (www.falconpl.org)
-
Below is a closure that's not a lambda, and this code worked before C++11. (I'll spare you the implementation of class Closure :)).
void fun1(int x, int y) { cout << x + y; }
void fun2(Closure<int> c) {
c(5);
}
int main() {
int x;
cin >> x;
fun2(new Closure(fun1, x));
}
-
Below is a closure that's not a lambda, and this code worked before C++11. (I'll spare you the implementation of class Closure :)).
void fun1(int x, int y) { cout << x + y; }
void fun2(Closure<int> c) {
c(5);
}
int main() {
int x;
cin >> x;
fun2(new Closure(fun1, x));
}
first of all, this code is incorrect :)
and second - closure is syntactic sugar that saves you a lot of typing.
manual implementation of syntactic sugar feature equivalent to this feature doesn't make it into this feature :)
-
Whatever, just making clear what is a closure and what is a lambda.
-
Just FYI- Python really is a utility language. Good for hobby projects, but it has pretty low performance compared to something like lua, which is also elegant in very similar ways. Lua is also industry standard for games, so... I'd recommend checking it out.
I find lua syntax ugly and way too verbose for a scripting language. And the language itself doesn't have some kind of standard 'ease of use' library. Each lua-based project invents it's own 'classes' and other infrastructure.
As for lua speed... Yes, in pure number crunching lua is good. But if you want to make some heavy computations, scripting language is hardly your choice. Other than calculations, when we use classes and other complex things, it's speed is more or less on par with python. lua's c/c++ interface is far from being convenient and far from being fast.
IMO lua is more suitable as some kind of macro/automation/plugin kind of language then something primary.
Syntax is a stylistic choice, and Python has second to none library support (the main reason it is used), but the rest of what you say is pretty bunk.
Lua really is a lot faster than Python, I know because I measured, and had to ditch Python after it became long in the tooth on certain computations running on an iPod touch. Another, less noted performance criteria, Lua fits with all of it's libraries in about 250kb, Python is comparatively enormous. This makes a difference on mobile devices.
Lua's C interface is also very fast (where did you get the impression it is slow? There is an overhead, but every scripting language that imports native functions has to incur a context switch cost), but if it's not fast enough for you then LuaJIT's FFI makes it insanely fast and as easy as writing C code in your Lua file. The C API is also simple enough to make a convenient wrapper in a single header file, thus removing error prone and aften buggy tools from the equation.
I don't really care what language anyone uses, but I needed to post this in case someone read your post and got the wrong idea.
PS> Have you tried to use Python's native bindings? If you think that Lua's C interface is inconvenient, then what adjective is reserved for Python?
PPS> I love Python, nothing against it, but lets call a spade a spade.
-
Lua really is a lot faster than Python, I know because I measured, and had to ditch Python after it became long in the tooth on certain computations running on an iPod touch. Another, less noted performance criteria, Lua fits with all of it's libraries in about 250kb, Python is comparatively enormous. This makes a difference on mobile devices.
Keyword is 'computations'. As I said - lua is good at numbercrunching. Definitely better then python.
But lua have it's own weak points, performancewise. For example iteration over table.
It is slower then the one in python. Call of closures is also slower, because of the way closures done in lua.
IMO table is overall weakest point in lua. 1 based array index? wtf?
Assign nil to erase item? wtf?
Lua's C interface is also very fast (where did you get the impression it is slow?
There is one thing in C interface that makes things a little ugly.
If you inject your object along with some methods into lua, in each
method wrapper you have to check type of 'self' to match your object's type.
Because there is no such thing as method, there are only functions,
and they can be called with any table as 'self' value.
PS> Have you tried to use Python's native bindings? If you think that Lua's C interface is inconvenient, then what adjective is reserved for Python?
I haven't used python for embedding, only as standalone language.
I find making C modules for python easy.
IMO if you care SO MUCH about performance of scripting language, you probably using it for wrong thing.
I know about performance of lua and python because I work on my own scripting programming language,
and I have to compare performance of various basic things, to make sure I'm doing everything right.
P.S. performance is important, but it's not the most important thing for scripting language. The most important, IMO, is ease of use. This is where python is far better then lua. There are several IDE's for python, but I haven't seen at least one complete for lua.
-
You can literally write blocks of and get C code performance if you need it via FFI. This includes arrays. It's even easier to use than Python's C interface.
-
You can literally write blocks of and get C code performance if you need it via FFI. This includes arrays. It's even easier to use than Python's C interface.
There is FFI module for python too, btw.
-
We are too smart to turn this into a language war.
I think my problems are elsewhere than in choice of language. Just generic lack of motivation..
-
No war intended, just combatting mistaken perceptions/loose language.
@Xecutor, I can't fault you for your taste in language, to each their own, but I think you are being a bit hyperbolic in your description of Lua. It's no big deal, but I don't want a newbie who is on the fence to get the wrong impression. I'd always recommend Python over Lua when putting together a desktop application or patching utilities together, and recommend Lua in the one place where it has clear and unambiguous advantages (embedding into engines).
PS. Embedding Python is really a non starter (as of 11 months ago, have not updated my knowledge since). I had to abandon a good Python codebase 3 years ago because my ambitions to port to various mobile systems hit a complexity wall. Maybe things are better now.
@OP: That said, learn JavaScript, so you can come to first hand grips with terrible design decisions and appreciate languages like Python and Lua more :)
-
and recommend Lua in the one place where it has clear and unambiguous advantages (embedding into engines).
That's what I wrote somewhere above. Lua is good as a sidekick.
But nowadays people are trying to write complete applications in Lua.
Which is IMO wrong.
There are several 7drls this year written in python and lua.
While reading python sources was easy, trying to understand what is going
on in more or less big lua codebase is non trivial.
And total length of 'local' keywords in pro lua code is sometimes longer than the rest of the code.
-
I will second Python. It's very easy to learn, quick to code, and has some interesting differences from other languages. I like that it requires precision but without a lot of extraneous typing (for example, the indentation of loops and other code blocks must be consistent, but you don't need lots of "{}" symbols that you'll lose track of).
If compilation errors due to mismatched braces are your biggest problem, then of course, languages that don't have braces are an obvious choice.
What I meant was, I like that a language is designed to force you to be precise. As in, there's almost always one best way to do something. (I am the exact opposite of whoever Perl was designed for.) But the way that other languages accomplish precision is to be extremely wordy (like Java) and/or clutter up your code with lots of brackets, parentheses, semicolons, etc. Python manages to be a precise language but is also very easy to write and easy to read.