Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What second language to use besides Scala for LowLevel? [closed]

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.

like image 993
Plankalkül Avatar asked Oct 30 '10 20:10

Plankalkül


6 Answers

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.

like image 169
dsimcha Avatar answered Nov 09 '22 05:11

dsimcha


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

  • BitC
  • Clay
  • D
  • Rust
  • Go
like image 41
missingfaktor Avatar answered Nov 09 '22 05:11

missingfaktor


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.

like image 35
Dean Wampler Avatar answered Nov 09 '22 05:11

Dean Wampler


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

like image 23
oluies Avatar answered Nov 09 '22 05:11

oluies


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).

like image 43
slugster Avatar answered Nov 09 '22 03:11

slugster


Like D and BitC, ooc (http://www.ooc-lang.org/) has a lot of features that appeal to a Scala (or Haskell) fan.

like image 34
user142435 Avatar answered Nov 09 '22 03:11

user142435