Are there any languages that have both high- and low-level facilities? If not, is it feasible to create one? Why or why not?

In theory, it would be very helpful to have a programming language that has both shell and regular programming language facilities, like Forth for example can easily be made to, and also to have high-level facilities; Forth does not seem (and it would probably take a good bit of work to make it) like a natural fit for high-level things.

Of course, languages like C or C++ can be made to simulate features of high-level languages, but at the cost of ugly or difficult syntax, and the addition of considerably more complexity, or at the cost of a lot of work, which would be unnecessary since it would often be easier just to use a more standard high-level programming language.

Clarification: Low-level meaning things like manual memory management, limited data structures, only one return value, and the like. Examples: Assembly language, C, C++ to some extent, and Forth.

High-level language examples would be: Python, Perl, JavaScript, Java and C# to a big extent, Lisp.

closed as unclear what you're asking by user40980, GlenH7, BЈовић, Dynamic, Martijn Pieters Jul 6 '13 at 9:14

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 7
    C++ is a high level language. – Raynos Dec 19 '11 at 3:40
  • Errr... Forth, C, and C++ are all high-level languages. Low-level languages consist of machine code and assembly languages. See en.wikipedia.org/wiki/Low-level_programming_language – Matthew Flynn Dec 19 '11 at 3:45
  • 1
    @MatthewFlynn It's quite funny that you are quoting the Wikipedia article that later on mentions: The terms high-level and low-level are inherently relative. Some decades ago, the C language, and similar languages, were most often considered "high-level" Many programmers today might refer to C as low-level. which is exactly what @dsimcha wrote... – yannis Dec 19 '11 at 4:17
  • 5
    Calling Java and C# high level to C++'s low level is hilarious. In a bad way. – DeadMG Dec 19 '11 at 4:37
  • 2
    C++ is a lower level language (lower than Lisp/Perl/Forth/etc.) indeed, since it provides no functionality for hiding low level features (i.e., it forces leaky abstractions), and there is a hard abstraction level cap which is not possible to break through. Forth is different - it is a decent meta-language, allowing building an unlimited number of abstraction layers. – SK-logic Dec 19 '11 at 7:44

C++ is the canonical example of a language that combines low-level and high-level features1. It doesn't simulate anything, it provides native support for almost every high-level construct you'll usually find in a common high-level language and almost every low-level construct you'll find in C.

But of course the terms are highly relative, there was a point in time (not that long ago2) where C was considered a very high level language. And there are quite a few other languages that offer considerable low-level functionalities while still commonly regarded as high-level, and vice versa, the lines are kind of fuzzy.

As for the syntax, that's something that naturally affected by the language's level of abstraction. Low-level generally means:

In computer science, a low-level programming language is a programming language that provides little or no abstraction from a computer's instruction set architecture. Generally this refers to either machine code or assembly language. The word "low" refers to the small or nonexistent amount of abstraction between the language and machine language; because of this, low-level languages are sometimes described as being "close to the hardware."

So naturally a low-level language adopts a syntax that's closer to machine code, which is inherently non human friendly. Quite a few languages, like C++, have adopted a wide variety of syntactic sugar, as a mechanism to make things easier to read or to express. But syntactic sugar is something that almost every high level language has opted for, C++'s sugar alone doesn't make it a low-level language.

As for the complexity of a low & high-level language, it's also natural: It's a tool with multiple goals, every single goal adds to its complexity. That's unavoidable regardless of the goal. High-level languages are not "better" than low-level one, they are just more concentrated on one goal. Languages that are designed with ease of use as a primary goal tend to be high-level, but that's only important if the necessary trade-offs to achieve the goal don't affect your applications.

Low or high level doesn't really matter, languages are primarily tools. You should choose the one that best fits whatever you're building in combination with what skills you have. Most popular languages are multi-purpose and Turing complete, in theory they are valid choices for building almost anything. There are no absolutes, of course, you may win in some areas if you opt for a high-level language and in others if you opt for a lower-level one, even within the same application.

Most large scale applications mix and match, following the "right tool for the job" mentality, and that's a more efficient approach, imho, than trying to have your cake and eat it too.

1 But please note that there isn't a definitive answer on what's considered a strictly high-level feature and what a low-level one.

2 In human years, in software years it was long ago...

  • 5
    +1: Calling Java and C# high level and C++ low level is laughable. – DeadMG Dec 19 '11 at 4:37
  • 2
    C++ does not provide many of the proper high level languages constructs. It does not provide a usable functionality for extending the language, it does not allow hiding the low level aspects of the language. It does not even contain a proper pattern matching, the most common feature of the modern high level languages. So it is indeed a much lower level language than most of those currently defined as high level. But I'd back DeadMG, it is dead funny to call C++, a language with at least some metaprogramming capabilities a lower level one to Java, which is not extendable at all. – SK-logic Dec 19 '11 at 7:50
  • 1
    @SK-logic The problem is with what's considered proper high level languages constructs. If this is my opinion vs yours, there isn't any point in discussing it further, we can just agree to disagree. But if you have some kind of reference, I'd love to see it. I think it'd be saner to approach the terms either historically (C++ currently is not considered a very high level language) or strictly in comparing two languages (Python is higher level than C++), and always loosely. But again if there are references I don't know about, please share. – yannis Dec 19 '11 at 7:59
  • 1
    @SK-logic I get it, I've read you comment on the question. But I once battled with assembly (lost that fight), since then everything else is high level to me. I'm not suggesting that the leaky abstraction barrier is not a sensible one, I won't go there. What I'm saying is that for relative and subjective terms every opinion is equally valid, and since there isn't a hard limit on how high we can go, what's considered high level changes considerably over time. – yannis Dec 19 '11 at 8:15
  • 1
    @SK-logic: Having done some Forth in the past, what aspects do you think are higher-level? Forth is firmly based on the stack, which isn't going to be abstracted out, and the word. In what way is the stack a higher-level concept than the class? I'm failing to understand what you mean. – David Thornley Dec 19 '11 at 16:44

C++ fits the bill to some extent if you use the right template metaprogramming tricks. D takes this to the next level. D has every low-level facility that C has except the macro preprocessor (which is made obsolete by a combination of a real module system and string mixins) and bitfields (which are implemented in the standard library instead).

On the high-level side, D is garbage collected, but the garbage collector is written in D and manual memory management can be done using C's malloc and free. The template metaprogramming system was designed with the help of Andrei Alexandrescu, the author of Modern C++ Design and is actually designed for readable metaprogramming beyond simple generics. It is advanced enough to allow high-level standard library modules like std.range, std.algorithm and std.parallelism.

Pushing the boundaries even further, I mentored a Google Summer of Code project last summer to create a matrix library in D. It's not production ready yet, but it allows matrix expressions to be written in a high-level form like the following, with the language inferring all the types and no unnecessary temporary matrices/vectors allocated:

auto m = matrix(
    [[1.0, 2, 3],
     [4.0, 5, 6],
     [7.0, 8, 9]]

auto v1 = vector([8.0, 6, 7]);
auto v2 = vector([3.0, 1, 4]);
auto v3 = vector([2.0, 7, 1]);

// .t is the transpose operator.
auto result = eval( inv(m * v1 * v2.t) * v3 );

I doubt even Matlab code would be much shorter or cleaner than that, and matrices are Matlab's home turf.

Not the answer you're looking for? Browse other questions tagged or ask your own question.