Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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.

share|improve this 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 Rizos 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
show 9 more comments

closed as unclear what you're asking by MichaelT, 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.

2 Answers

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

share|improve this answer
5  
+1: Calling Java and C# high level and C++ low level is laughable. –  DeadMG Dec 19 '11 at 4:37
1  
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
    
Despide not agreeing at all on calling C++ a high level language, +1 for renaming a lame, idiotic term "general-purpose language" to a much more correct "multi-purpose". –  SK-logic Dec 19 '11 at 7:51
    
@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 Rizos Dec 19 '11 at 7:59
    
@Yannis Rizos, for me the division between clearly low-level languages and high level languages is in the ability to hide any of the lower level (no matter what level it is) constructs from the higher levels of abstraction. You can't do it with C++ - there will always be functions, classes, methods, variables, types, etc. You can't hide any of that low level concepts. In the true high level languages, even as trivial and basic as Forth, any such constructs can be abstracted out. So, presence of the leaky abstraction is a clean barrier. –  SK-logic Dec 19 '11 at 8:06
show 4 more comments

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 );
writeln(result.pretty);

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

share|improve this answer
add comment

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