Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 [2] 3 4 ... 7

Author Topic: What programming language?  (Read 17404 times)

zwei

  • Bay Watcher
  • [ECHO][MENDING]
    • View Profile
    • Fate of Heroes
Re: What programming language?
« Reply #15 on: May 12, 2010, 10:15:32 am »

Yeah, I know I'm probably degenerating this into a pointless argument, but I'm tired of reading "Python can't be used for large projects" every turn, stated as a tried and proved truth. easiest way to find out about some more notable Python projects is here: http://www.python.org/about/quotes/

Youtube and EVE Online are a couple notable examples of large Python projects.

EVE Online uses Python, but it is not entirely written in Python. There is nothing wrong with Python for large projects, but it is an interpreted language so it relies on an interpreter which will be written in another language.

Which is not issue because what makes and destroys performance lies in used algorithms.

Typical cautionary tale involves programes who rewrites O(2^n) algorithm from java-interpeted scripting language (yeah!) to ultraoptimized assembler to see pretty much zero performance gain while other rewrote it as O(log(n)) without language change.

Its writing smarted that makes difference.

Urist McDepravity

  • Bay Watcher
    • View Profile
Re: What programming language?
« Reply #16 on: May 12, 2010, 10:19:25 am »

In other words, parallelizing it becomes much harder. Impossible, for large projects, and we all know DF could do with some of that.That's a general problem with imperative languages, though, not just C++.
Only when it was designed as single-threaded app. In general, C++ has no problems with parallelization.
Logged

Thief^

  • Bay Watcher
  • Official crazy person
    • View Profile
Re: What programming language?
« Reply #17 on: May 12, 2010, 12:06:59 pm »

EVE Online uses Python, but it is not entirely written in Python. There is nothing wrong with Python for large projects, but it is an interpreted language so it relies on an interpreter which will be written in another language.

All the EVE core (renderer etc) is C++, the Python is basically scripting. It's also not "normal" python, it's their own brand "stackless" python.

Typical cautionary tale involves programes who rewrites O(2^n) algorithm from java-interpeted scripting language (yeah!) to ultraoptimized assembler to see pretty much zero performance gain while other rewrote it as O(log(n)) without language change.
Yeah, especially as Java bytecode is either JIT compiled (pc) or natively executable (mobile/embedded) these days. It's not as slow as it has a reputation for any more.
Logged
Dwarven blood types are not A, B, AB, O but Ale, Wine, Beer, Rum, Whisky and so forth.
It's not an embark so much as seven dwarves having a simultaneous strange mood and going off to build an artifact fortress that menaces with spikes of awesome and hanging rings of death.

DaveT

  • Bay Watcher
    • View Profile
Re: What programming language?
« Reply #18 on: May 12, 2010, 12:38:46 pm »

FP languages most certainly ARE used in big projects (phoned lately to someone? ever wondered in what language call-routing was implemented?). It is just that they are not really thing of trendy kids but rather serious gentlemen (who will refrain from using it if it is not apropriate).

Problem is that people try to transalte oop/imperative code-monkey experience to fp. It certainly sounds like headache if you ever saw bigger project. It is something that actually needs experience on big FP project before you can assess it.

Not necessarily true. One of the major Class 4/5 softswitch providers in the U.S. has their primary software written entirely in C.
Logged

axus

  • Bay Watcher
  • Axe Murderer
    • View Profile
Re: What programming language?
« Reply #19 on: May 12, 2010, 12:46:36 pm »

In other words, parallelizing it becomes much harder. Impossible, for large projects, and we all know DF could do with some of that.That's a general problem with imperative languages, though, not just C++.

So what you're saying is, that if DF had been written in a functional language, it would have been easy to use all the CPUs in a quad-core system?
Logged

zwei

  • Bay Watcher
  • [ECHO][MENDING]
    • View Profile
    • Fate of Heroes
Re: What programming language?
« Reply #20 on: May 12, 2010, 01:02:28 pm »

In other words, parallelizing it becomes much harder. Impossible, for large projects, and we all know DF could do with some of that.That's a general problem with imperative languages, though, not just C++.

So what you're saying is, that if DF had been written in a functional language, it would have been easy to use all the CPUs in a quad-core system?

In short, yes. FL features and code style by default mesh very well with paralelization.

Baughn

  • Noble Phantasm
  • The Haruhiist
  • Hiss
    • View Profile
Re: What programming language?
« Reply #21 on: May 12, 2010, 03:26:06 pm »

It's true that it's easier to multithread C++ if you're doing so from the start, but it still isn't easy; it's very hard, especially for something like DF. Doable, though, as opposed to converting a large single-threaded program - that's just impossible.

Haskell, in comparison, makes it easy to multithread your program from the start, and.. well, not exactly easy, but not terribly hard to retrofit threading. If it's well designed, even without threading in mind, there are many ways to retrofit threading that allow no possibility of altering semantics whatsoever. In other words, no race conditions, no deadlocks, no nothing. It also has a very nice Software Transactional Memory implementation.

Haskell is, not to put too fine a point on it, mature. It's a compiled language with speed often approaching C even without dipping into its very well-made FFI, it has a reasonably large number of libraries available on Hackage along with the infrastructure to easily deploy them, and the language is one of the most theoretically advanced on the planet while striking a good balance between purity and practical usefulness - there aren't many exceptions to the rules, once you understand the fully general rules. You can learn it in far less time than it would take to fully learn C++.

Other functional languages.. well, some of them are more advanced theoretically, and many are very useful for theoretical work. I don't know of one that is as generally useful as Haskell, though.

It's no coincidence that it's increasingly being hyped as the language of the future for parallel programming. :)
Logged
C++ makes baby Cthulhu weep. Why settle for the lesser horror?

czolus

  • Bay Watcher
    • View Profile
Re: What programming language?
« Reply #22 on: May 12, 2010, 09:18:19 pm »

It is a pain in the ass to convert C++ code designed for single-threaded operation into a multi-threaded program.  Really, in that, I'm reminded of assembly and how I was taught, "Its like working with concrete: Its generally just easier to rip it all out & start fresh than try to work around what's already there."

With that, its fun to note the almost religious significance most of us programmers assign to our language(s) of choice.  Myself, I prefer hybrid languages that will allow me to program on any level from inline assembly to functional (I'm not a huge fan of logic-programming, yet) within the context of the same block of code---use the best tool for the job.
Logged
Sic sum in ignis; sic sum quiritatio

Shrike

  • Bay Watcher
    • View Profile
Re: What programming language?
« Reply #23 on: May 12, 2010, 09:25:44 pm »

Considering it's a drama engine, it should have been written in Shakespeare.
Logged

Black

  • Bay Watcher
    • View Profile
Re: What programming language?
« Reply #24 on: May 12, 2010, 10:19:58 pm »

As someone who enjoys programming in both C++ and Haskell, I have to say that DF would have far fewer bugs and be much easier to maintain if it were written in Haskell. The more expressive type system catches more errors, the paradigm of purity makes it very easy to reason about the operation of a program, and the first class functions, higher order functions, and lazy evaluation make it very easy to create complicated algorithms from simple ones. The purity is also one of the reasons why Haskell is so easy to thread. There are no race conditions in pure code, the only thing that factors into parallelism is data dependency. Impure operations in Haskell exist only in localized sections and are usually much more straightforward than in other languages.

There are problems though. It is harder to reason about the performance of Haskell code because of lazy evaluation. There are pitfalls and gotchas that can lead to far more memory usage than is required. On the other hand, lazy evaluation can improve the performance of code in inner loops, because that which is not required is not evaluated. Another problem is that Haskell cannot work with C++ libraries without serious work- C is fine though. This is important as C++ libraries are very common and very useful. One thing that particularly got me early on was the compilation errors: They tend to be cryptic when there is a parse error, and until you get used to the richer type system, the type errors are pretty hard to decipher for a beginner.

So in the end, Haskell is a sweet language for really complicated projects because it makes the complexity more lucid and easier to reason about. There's also that Haskell code is almost always shorter than the corresponding C/++ code. One example is parsing. A parser in C written in a thousand lines can sometimes be written in 30 lines using the appropriate parsing library in Haskell!

On the other hand, C++ is not a bad language if you are a disciplined programmer who knows how to design their code. There are a thousand different ways you can overdesign in the wrong direction and screw yourself, particularly with OOP. But if you are awesome at it, C++ gives you a great deal of power in multiple ways. Performance reasoning is easier, you have all the C/++ libraries you could ever want, and you can write the program at the level of abstraction you like.

If I could take any features from Haskell and put them in C++, it would be Algebraic Datatypes and first class functions. Those would make C++ the ultimate compiled imperative language.

@Baughn: Are you the same Baughn who hangs out in #haskell on freenode? :)
Logged

Justice

  • Bay Watcher
    • View Profile
Re: What programming language?
« Reply #25 on: May 12, 2010, 10:36:23 pm »

I tend to use different languages for different tasks.  Python is nice for small modules that can be edited while the game is running, and I've used it in one of my MMOs for things like the ability system, object interactions, and various rules-based stuff.  Other games have used Python for stuff like UI (largely because you can easily modify it while the game is running, and allow users to easily extend it) and parts of their AI (for basically the same reasons).  It's generally quick for a scripting language, isn't a memory hog, and is easy to use within C++ programs.  Other than that, at home, I've pretty much kept all game code in C++, and tools in whatever seems easiest for the task (which is usually perl, C, C++, occasionally C#, or a bash script). 

Everyone in my current studio has had to deal with *iprobablyshouldn'tnamethis*Script, however, which has basically all of the possible disadvantages of a scripting language and none of the advantages - not even compile time, since a lot of changes require a C++ recompile of most of the project.  And carries with it giant overhead on all game objects used with the engine and garbage collection of death that adds 60ms to the frame time every few minutes.  So they are kinda downers on using any scripting for anything, client or server.  Also, actionscript for the UI, since the UI is Flash, but that is slow as the circus and we tend to migrate the code to C++ for performance reasons (generally at least 15x speed difference, often a lot more) once we're past prototyping a given widget.  So basically everything at work is C++.  It would require some C/C++ work at minimum to interface with the PS3 APIs regardless, even if we had a decently fast PS3 compiler for something else (GCC isn't terribly good at optimizing for PS3), and pretty much all big studio games are C++ because basically all experienced game programmers use C++, and studios want to hire experienced people.  Also, all the big engines and libraries we use tend to be C or C++.

For anything other than Big Studio Projects though, most any language works ok, as long as the performance and compatibility issues with it are acceptable to you for the game and you can handle the overall complexity in that language (games are pretty complicated beasties).  Even a garbage collected language is fine if your game loop is quick enough or dropping a frame here and there is irrelevant - in Dwarf Fortress, that kind of thing wouldn't be noticeable, though the performance penalty from using any scripting language would be pretty rough.  In a shmup, the last thing you want to do is suddenly drop a frame here and there (serious shmup players hate that), but as long as you can push out a frame every 33ms, it doesn't matter if you could have got it to 27ms by using a language with less overhead (assuming the traditional shmup game loop design, which I call "What is this time thing you speak of?").


Edit: Oh, I have no experience with FP, so I can't comment on how useful it is for games.  I can say that I've used approximately 0 non-C libraries in C++ game development (At home and college, at least.  Not true of licensed stuff at work, but most of that I would never use by choice anyway.) that aren't for things typically built in to more modern languages or have equivalents in most languages (standard containers, <functional>, <algorithm>, etc), as most important libraries have C interfaces anyway.  Any hard to track memory overhead tends to be a killer for low memory console development but on PC it just depends.  I keep thinking I should take a look at FP, but I feel like I need a good block of time for it, and right before E3 blocks of time are hard to find.
« Last Edit: May 12, 2010, 10:53:34 pm by Justice »
Logged

Baughn

  • Noble Phantasm
  • The Haruhiist
  • Hiss
    • View Profile
Re: What programming language?
« Reply #26 on: May 13, 2010, 01:11:15 am »

Black: Yep. Near as I can tell, I'm the only Baughn anywhere, which is certainly convenient.
Logged
C++ makes baby Cthulhu weep. Why settle for the lesser horror?

Sowelu

  • Bay Watcher
  • I am offishially a penguin.
    • View Profile
Re: What programming language?
« Reply #27 on: May 13, 2010, 01:50:19 am »

I'm going to pimp C# here to my fellow programmers because, well, because I can.

The latest version has lambda expressions.  That is the extent of my pimping.
Logged
Some things were made for one thing, for me / that one thing is the sea~
His servers are going to be powered by goat blood and moonlight.
Oh, a biomass/24 hour solar facility. How green!

Baughn

  • Noble Phantasm
  • The Haruhiist
  • Hiss
    • View Profile
Re: What programming language?
« Reply #28 on: May 13, 2010, 02:01:35 am »

Sort of windows-only, though. I enjoy running DF on linux. :P

While you're in there, what about F#?
Logged
C++ makes baby Cthulhu weep. Why settle for the lesser horror?

Sowelu

  • Bay Watcher
  • I am offishially a penguin.
    • View Profile
Re: What programming language?
« Reply #29 on: May 13, 2010, 04:06:19 am »

Never touched F#, don't even really know what it is.  And I was so certain that Mono let you compile C# on Linux, too.  With the amount of MS apps that are written in C# these days and which are sold on the Mac, I'm pretty sure C# is compilable on Macs as well.

Edit:  Ah.  Mono's only up to C# 3.0 so far.  4.0 is awesome and kicks ass.
Logged
Some things were made for one thing, for me / that one thing is the sea~
His servers are going to be powered by goat blood and moonlight.
Oh, a biomass/24 hour solar facility. How green!
Pages: 1 [2] 3 4 ... 7