views:

318

answers:

10

Hi

I am absolutely happy with Scala and just love it :)

But sometimes I really want to go a bit more "low level", without a JVM and using "cool" CPU-Features like SSE etc.

So what would be a good second language besides Scala?

It should be:

  • Compiled to machine code
  • Easy usage of C-libraries
  • Possible to program very close to the hardware
  • Possible to program in a very highlevel-way when I want to

So basically I want a Scala where I can just throw in inline assembler when I want to :) I assume, that such a language does not exist, but maybe there are some that come close.

So what would be a good choice? C++?, D?, OCaml?

I programmed a bit in C++ (15 Years ago) and very little with OCaml. In both cases, I only solved a few problems and never got very "deep" into the language itself.

+5  A: 

I'm thinking about this, too, as I'm currently doing a C project and feeling very unproductive, also missing Scala. (I also did a lot of C++ in the Pleistocene...) I may switch to go. D also looks attractive.

Another option, if it makes sense for the problem, is to use C + a scripting language, like Lua or Ruby. It's what Unix+shells and emacs have done forever. You get performance and low-level bit twiddling when you need it and productivity when that's more important.

Dean Wampler
+2  A: 

Something that fits your requirement is C/C++, as you can inline assembly language with regular code. Calling C libraries will be natural :)

Another thing that fits is the HLA implementation of assembly language (wiki article here) - it is assembly with a lot of high level constructs to make things easier (and faster) for beginners to learn (it compiles to "proper" native code).

slugster
+8  A: 

You're pretty much describing D.

  • Compiled to machine code: Check. There is an experimental .NET VM implementation, but all three major implementations (DMD, LDC, GDC) compile directly to native code and the language is designed to make native compilation feasible.

  • Easy usage of C libraries: D supports the C ABI and all C types. Pretty much all you have to do is translate the header file and link in the C object file. This can even be partially automated.

  • Possible to program very close to the hardware: Check. D is what I'd call an idiomatic superset of C. It does not support every piece of C syntax, its module system is completely different, static arrays are value types in D2, etc. However, for any construct in the C language proper (i.e. excluding the preprocessor) there is an equivalent construct in D or the standard library. For any piece of C code (excluding preprocessor abuse) there is a canonical D translation that looks roughly the same and should generate the same assembly language instructions if you're using the same compiler backend. In other words, every C idiom (excluding preprocessor abuse) can be translated to D in a straightforward way.

    The reference implementation of D also supports inline ASM, so you can mess with SSE, etc.

  • Possible to program in a very highlevel-way when I want to: Check. D is designed to be primarily garbage-collected language (though you can use manual memory management if you insist and are careful not to use library/runtime features that assume GC). Other than that, high-level programming is mostly implemented via template metaprogramming. Before you run away, please understand that template metaprogramming in D is greatly improved compared to C++. Doing template metaprogramming in D vs. C++ is like doing object oriented programming in C++ vs. C. In D template metaprogramming is designed into the language, whereas in C++ there are just enough features that you can use clever hackishness to make it barely work. The same could be said for object-oriented programming in C++ vs. C. The std.algorithm and std.range modules of Phobos are good examples of the high-level subset of D.

dsimcha
Real men program in C using a text editor ;-)
Blank Xavier
+1  A: 

You should take a look at Go.

Eric Bowman - abstracto -
+3  A: 

There's a programming language that, although really just a technology demo at this point, looks like it might fit your needs if and when it matures. That language is called Clay. Some highlights:

  • LLVM based
  • Whole program type propagation
  • Concise syntax
  • No GC
  • C interoperability
  • Compile-time meta-programming
  • SIMD programming
  • targeted to system programming
  • open source, liberal license

It's one to keep an eye on.

ergosys
+4  A: 

Here are some that satisfy the criteria mentioned in your question:

missingfaktor
+4  A: 

C++0X, Erlang and maybe Haskell and Go. C++ and Erlang has a strong user base and there is many jobs avaliable with C++0x and Erlang. (I am uncertain how good the C/C++ interop is with Go)

C++0X ("cee plus plus oh ex") is a good option. It has lamda functions and other good stuff.

Walktrough of C++0X TechDays 2010: Modern Programming with C++0x

Also C++0X has good Generics support as documented in Type Classes as Objects and Implicits, Oliviera, Moors, Odersky, OOPSLA 2010. See their Figure 12 below:

Figure 12 from Type Classes as Objects and Implicits

oluies
+1  A: 

It's still very new, but take a look at Vala. It's a sweet layer of syntactic frosting upon the GObject cake and compiled to pure C.

It supports features like closures and limited type inference.

bse
+1  A: 

Think about using C or C++ for the very lowest level programming, and then wrapping that with JNI or JNA in a Scala library. In some cases, you can have your cake and eat it too this way.

Rex Kerr