-19

This probably isn't a new or different complaint. In fact, I'm probably just blowing off steam because a perfectly legitimate question about facts, to which factual answers were and are entirely possible, got closed as "subjective.

Why are some compiled languages slower than others?

This may sound like a silly question, but I wonder because, to me, it seems that a programming language is merely a notation of operations. Broadly speaking, it all seems to come down to the compiler in the end. I can hardly imagine that a language is designed in such a way that the compiler cannot optimise code written in it in the same, or at least similar way that would be possible in other languages. Is this the case, however, or is there another reason behind it?

The fact remains: the people who voted to close this as subjective clearly don't understand the subject matter. I'd almost bet not a single one of them has written a single compiler (or even code generator for a compiler) in their life. Even without that experience, however, anybody who writes code at all should have a clue about the fact that the result of a program (the code generated by a compiler, in this case) is a result of the code that was written, and what it has to do.

I suppose you can argue that the code people write as parts of compilers can be influenced by their opinions (just like any other code is), but if we use that as a basis then SO might as well be shut down immediately, because every question is entirely subjective. Clearly that's not a reasonable basis for deciding what answers really qualify as "too subjective".

Edit: the difference between SO and M.SO is interesting. On SO it's closed because people read the question but didn't really understand the subject matter. Here on Meta, people proclaim that it's too broad because they apparently don't even understand English, or just didn't read the question itself, so they read "does X exist" as being too broad because it's impossible to list every possible X.

9
  • 8
    The correct close reason for that question is too broad, at the very least it's the far more appropriate and understandable reason. I can see a justification for subjective, but you kinda have to work harder to get there. It's pretty unambiguously and obviously too broad.
    – Servy
    Commented Jul 17, 2014 at 15:08
  • "speed" of a program is not a quantifiable as you seem to think it is. There are a number of factors which affect speed, ranging from the processor speed to the type of hard drive, and those factors will change when you run the program on a different machine Commented Jul 17, 2014 at 15:08
  • 3
    @SamIam: are you honestly questioning whether it's possible to time how long it takes for code to execute? Of course the time varies with the hardware, but that's of precisely zero relevance to the question. Commented Jul 17, 2014 at 15:20
  • @Servy: yes and no. Of course it's not possible to list every design decision that a language could possibly make, and how that relates to the speed of compiled code. But also yes, it's entirely possible to give some reasonable examples of design decisions and how those decisions influence the speed of generated code. Commented Jul 17, 2014 at 15:21
  • 8
    @JerryCoffin So it's possible to provide an incomplete post that doesn't actually fully answer the question, but it can provide just a tip of the iceberg that is the answer. That's a telltale sign that the question is too broad. A complete answer cannot be given. This question is so broad that even entire books or full college courses on the subject couldn't cover it completely. The question needs to be way, way, way more specific for it to be answerable.
    – Servy
    Commented Jul 17, 2014 at 15:26
  • @Servy: Okay, so shut down SO immediately, because if you want a truly complete answer, the same is true of every question on SO. Commented Jul 17, 2014 at 15:28
  • @SamIam: Yes, zero relevance to the question (at least to the question of whether the original question should be closed). The original question is about language design. Yes, a good answer will probably at least mention the degree to which a language specifies properties that are more or less difficult to translate to specific assembly languages. Commented Jul 17, 2014 at 15:30
  • @Clive: Read the comments. Those claiming it's too broad are attempting to read "does X exist?" as meaning that a complete answer must list every possible value of X. It's pretty obvious their understanding of the simple English in the question if badly flawed. Commented Jul 17, 2014 at 15:45
  • 2
    @JerryCoffin, some high-rep users here seem to complain about the flow of bad questions and the fact it seems difficult to find anything they consider sufficiently interesting to answer (I must say I've had this feeling too). Perhaps once you've answered enough narrow questions, you're just finding it more interesting to answer questions that are a bit broader in scope (like this one), which could lead to a good answer with a few paragraphs. Perhaps it's not the newbie questions that drive high-rep users away, rather it could be the fact that answerers "outgrow" the constraints of SO.
    – Bruno
    Commented Jul 17, 2014 at 16:16

3 Answers 3

11

I don't believe that it's really opinion based, but the question in its current form is much too broad.

There are hundreds of different optimisations in general and dozens of different languages to talk about, which makes this ridiculously difficult to address in a single answer.

If the question instead asked about a specific optimisation and why a language could not take advantage of this optimisation, that would be more appropriate.

Even within the tagged languages , and , there are different assumptions that can be made about what a particular piece of code can do (all of these languages have different levels of "safety") in each of these different languages, which could take up at least a few pages to talk about.

For the benefit of <10k, here's the question (which has now been deleted):

Why are some compiled languages slower than others?

This may sound like a silly question, but I wonder because, to me, it seems that a programming language is merely a notation of operations. Broadly speaking, it all seems to come down to the compiler in the end. I can hardly imagine that a language is designed in such a way that the compiler cannot optimise code written in it in the same, or at least similar way that would be possible in other languages. Is this the case, however, or is there another reason behind it?

21
  • Now that i see the question (since I am <10k) it sounds like a valid question. And in fact your answer to this meta sounds like a start of a valid answer. Though I would like the question to specify what part is slow... is it "compiling" slowly or "running" slowly. Commented Jul 17, 2014 at 15:14
  • @ArchimedesTrajano: the OP says "optimise code" in the question, so I'd presume it's the performance of the running code rather than the time taken to compile it. The main goal of a compile is to improve running performance anyway. Commented Jul 17, 2014 at 15:16
  • 6
    @ArchimedesTrajano if the answer can only start with "there's a thousand different optimizations and talking about all of here them is ridiculous", then the question is useless. Also, the fact that it's tagged java, c# and c++ makes it even worse as the user doesn't seem to know that java introduces an additional level of indirection over c++ due to being compiled to bytecode and then executed in a vm. You would also have to explain all differences due to the separate programming paradigms of the languages, and so on. Thus it's just entirely too broad.
    – l4mpi
    Commented Jul 17, 2014 at 15:19
  • @l4mpi: Consider the irony of your fitting a reasonable description of one of the major factors into a comment, but still claiming that it can't fit into an answer. Commented Jul 17, 2014 at 15:24
  • 7
    @JerryCoffin But it's still not a complete answer to the question. It's just the very start of a lengthy explanation of just one of many thousands of things to talk about. When a question is too broad it's super easy to start talking about just one tiny little piece of the puzzle. A broad question isn't a question in which nobody can provide any useful information at all. That's an unclear question. The problem with a question that's too broad is that no matter how much information you provide, it will never be enough.
    – Servy
    Commented Jul 17, 2014 at 15:30
  • The java C# and C++ tags are probably useless as it adds unneeded specificity to the question. I just just compiler and optimization tags are enough. However, couldn't the answer to this have some more common optimizations be brought up? I am not claiming to be a compiler expert, but I would guess something along the lines of knowing how the processing pipelines of a CPU so they can move code around to make it go faster would be part of it. Commented Jul 17, 2014 at 15:30
  • It may need something along the lines of stating whether it is "managed" code or not. Though because of the Java and C# tags I would assume it is "managed" code so it's not really the compiler, but the VM it is running on. Though in that case optimizations do not make sense as much because there's a separate compilation phase at runtime. Commented Jul 17, 2014 at 15:33
  • 1
    @Servy: Except that in this case it clearly is enough. Reread the question. The basic question is not asking about every possible language design decision that could influence speed of generated code. It's asking about whether such things exist or not. A good answer requires only one good example of such a thing, not an exhaustive list (though a few examples would undoubtedly be better than only one). Commented Jul 17, 2014 at 15:34
  • 1
    @JerryCoffin That's basically interpreting it as a list question then, which is still not an appropriate SO question. Also just see the text of the close reason for "Too Broad", it applies exactly to this question.
    – Servy
    Commented Jul 17, 2014 at 15:38
  • 5
    @JerryCoffin I've named one reason for this, I did not explain it in the detail I would guess the OP of the question needs to thoroughly understand it. Also, as Servy says, this is just one piece of the puzzle; even restricting the question to two bytecode-languages would still be rather broad. And only naming a single example why this can happen doesn't seem useful. There's no definite, complete, factual answer IMO, thus -> too broad. And for the record, I did write a compiler in university and a number of interpreted DSLs for work and fun since then :)
    – l4mpi
    Commented Jul 17, 2014 at 15:38
  • 1
    @Servy: Those claiming that it's too broad are the ones trying to interpret it as a list question--"list all the reasons a compiler might produce faster code from one source language than another." The question is "Does X exist?", not "list all values of X." The former is answerable. Commented Jul 17, 2014 at 15:43
  • 5
    @JerryCoffin and the question "Does X exist" is utterly trivial and thus useless. Of course it exists, otherwise all languages would have the same speed. How is answering the question by saying "Java and C differ in speed due to thousands of factors, one of them being that java is compiled to bytecode and interpreted in a vm, which introduces a level of indirection" useful? Even disregarding the fact that everybody who spends 10 minutes reading about how java and C are compiled and executed should already know this?
    – l4mpi
    Commented Jul 17, 2014 at 15:50
  • 1
    @l4mpi: You seem to be missing yet another point. In his case, "X" is not "do differences exist?", but "are there reasons differences must exist?" In other words, are the differences that exist simply due to differences in how the compilers are written, or really traceable to differences in the languages themselves. Different C89 compilers (for example) also produce different code, but in this case the differences clearly are not traceable to the language since they all compile the same language. Commented Jul 17, 2014 at 17:28
  • @JerryCoffin wouldn't that answer be equally trivial? "No, there's no reason these differences must exist as you could in theory write a compiler that results in the optimal machine code representation for the given program (and machine), which would of course be the same for equivalent programs regardless of the language they are written in. In practice, this doesn't happen because of the thousands of factors above." Still not an useful answer; probably still above OPs head. I can't think of any good answers, can you describe what you think would be a satisfactory answer to the question?
    – l4mpi
    Commented Jul 18, 2014 at 6:51
  • 1
    @l4mpi: On a completely theoretical level, you could be right that a sufficiently intelligent compiler could work past all differences in source language. In reality, we have factors like aliasing in C and C++ that make it much more difficult to produce as good of code with them as with Fortran (which only allows aliasing in a very controlled way, via common blocks). A good answer could describe what aliasing it, how it arises, and how it hurts code generation (all fairly easy to describe in sufficient detail to be understandable to relative beginners). Commented Jul 18, 2014 at 13:09
5

A true expert on compilers could probably write a series of really good essays about how certain language features affect the optimizability (is that a real word?) of a language; possible even expressed in language that a passing decent programmer without deep experience in compilers could follow. I'd love to read that series even though I'm unlikely to ever implement a compiler for a Turing complete language again (and the only one I've done was a crappy, recursive-descent, immediate-code-generation toy modeled on the Crenshaw tutorial).

But ...

  • The current expression of the question is horrible. That should be correctable, but it does lead me to wonder if the OP even has the background to understand the answer.

  • Really good answers to this questions are going to be big. Like I said: a series of essays or a short book. You might squeeze a decent one into the character limit for posts but it would certainly be a very long post by Stack Exchange standards.

I'm a little surprised at the close reason chosen, but not enormously because most merely decent programmers don't seem to know the subject in any depth but do seem to have strongly held opinions on the matter. Reading the pure amount of verbiage spilled on Programmers on related topics is telling.

If someone wanted to fix the text I could get behind a movement to undelete and re-open, but my money is on lots of crappy answers, a few informed ones addressing some part of the problem or another and very few or none that really tackle the whole problem.

1
  • 1
    Yes, a really good answer would be a lot longer than the average answer on SO, and yes, the original question could certainly benefit from some editing. Unfortunately, no matter how well it's reworded, it appears to me that even if you wrote a great answer ahead of time, it'd be open to question whether you get the question open and paste an answer before it was closed again. The claimed intent of SO is to promote great answers, but now seems intent on closing any and all questions to which truly great answers are even possible. Commented Jul 18, 2014 at 5:15
4

I mostly agree with dmckee, but it doesn't appear that anyone here has directly answered the question you asked...

Something I've noticed in myself over the years is a tendency toward scanning new questions looking for common anti-patterns. New users tend to make the same mistakes again and again, and after a while you start to just expect them. At first glance, this question appears to fall into the same boat as countless previous questions of... mixed value:

...you get the idea. Sometimes these sorts of questions get decent answers; sometimes, they're asked in good faith. Often, they get a lot of attention simply because they're the programmer equivalent of "the Raiders are better than the Broncos, amirite?"

So I strongly suspect that folks read the question you're referencing and thought, "great, another excuse for a language pissing contest - nope."

Not because it couldn't be answered well. Because it probably wouldn't be answered well.

In all honesty, if you or someone else wanted to write a really comprehensive answer to a question like that, it might do a lot of good just to have it out there, if nothing else as something to point to the next time one of these questions comes up rather than launching into a debate over language idioms.

2
  • So would you say that people are careless in closing these sorts of questions based on a "quick scan" of the question, or is it valid for a person to vote to close these sorts of questions based on what they've seen before? Commented Jul 20, 2014 at 1:08
  • Both of those statements are true, @Qantas. Hence the difference between the reason the question was closed (opinion-based) and the criticisms raised here on meta (too broad).
    – Shog9 Mod
    Commented Jul 20, 2014 at 2:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .