5

I recently started researching about coding, but there are a few things that made me confused. I chose Visual Studio Code to start coding in C and Python (I was using IDLE for Python before), but afterwards I learned that Visual Studio Code does not contain compiler or other components that I don't know what they do, so it's not an IDE, although it works for code that needs to be compiled or interpreted.

It's said that it's just an editor. But it works for both interpreted and compiled languages. I'm confused: Should I use Visual Studio instead?

3
  • Note that Visual Studio Code is in no way special in this regard. Virtually every IDE will simply invoke an external compiler process for many reasons. Visual Studio, Eclipse, XCode, Rider,. What is usually included is a parser for the various languages to allow syntax highlighting.
    – Voo
    Apr 29, 2021 at 9:38
  • @Voo: Visual Studio actually runs a C++ compiler continuously, for its Intellisense features. Figuring out whether a C++ token represents a variable, function or a type can't be done by simple parsers, not to mention the infamous >> token in std::vector<std::vector<int>>.
    – MSalters
    Apr 29, 2021 at 10:32
  • @MSalters So Visual Studio has an in-process c++ compiler? Fascinating, but given the complexities of C++ that makes sense.
    – Voo
    Apr 29, 2021 at 12:26

5 Answers 5

15

Compilers aren't magic - they're just programs, which can be run from the command line. Visual Studio Code has a "Terminal" tab in the bottom pane of the default UI, where you can invoke the compiler. (For non-trivial applications, you probably wouldn't be running the compiler directly, but would instead be running some software that also handles linking and other stuff; in a Linux-style environment that might be make, or ant for Java.)

But retyping the compiler invocation gets old pretty quickly, so Visual Studio Code has some shortcuts available. In the "Terminal" menu there are entries for "Run Task" and "Run Build Task" - if you select one of these, Visual Studio Code will present you with any auto-detected tasks it can come up with from what your project looks like.

3
  • 10
    (As a note, Ant is obsolete; Maven and Gradle are the modern Java build tools.) Apr 29, 2021 at 4:44
  • 3
    Apache Ant is still maintained, and released a new version this month. It may not reflect the build approach most organisations favour nowadays, but its maintainers do not consider it obsolete.
    – James_pic
    Apr 29, 2021 at 10:42
  • There are some tasks that are simpler to be delegated from maven to ant. Thanks to the maven ant plugin :D
    – Walfrat
    May 7, 2021 at 7:52
5

While it doesn't compile by itself, it uses extensions that you can download to do it.

It's an IDE, but supposedly works for everything, so I guess that by not having all the possible options pre-installed you can reduce the amount of space the application requires.

5

It’s the same with your favorite word processor: while it can correct your misspellings or even grammar errors in English or other languages, your word processor does not understand anything from the text and will not execute any instructions in English that you may type with it.

A coding editor like Visual Studio Code, Atom, Sublime Text and others are exactly like that: they do absolutely not know what the code is supposed to achieve. Nevertheless, they are able to parse the grammar to see if what you type is compliant with your programming language grammar.

5

But ... Visual Studio Code is an IDE.

Sure, it doesn't ship its own compiler -- but it sure does integrate those you need via extensions.

As others have already said, compilers are just programs, so they can be invoked from the command line.

Furthermore, a modern approach to syntax highlighting, code-assist and refactoring is the so-called Language Server Protocol (LSP). Most major IDEs -- at least IntelliJ IDEA, Eclipse, and Visual Studio Code -- understand the LSP. If a language server is available for the target language, Visual Studio Code can interact with the language server. In case of Java, this is exactly what happens. There is a plugin for Eclipse JDT that offers the power of Eclipse code-assist and syntax highlighting as a language server. Visual Studio Code interfaces with that. The Visual Studio Code Java Extension ships with Eclipse JDT and integrates it -- and the incremental Eclipse compiler -- via the LSP.

For other languages, where a language server is not available, a Visual Studio Code extension might opt to do the parsing itself. Still, if an interpreter or compiler is available, Visual Studio Code will integrate with those for the final step (compilation and/or execution).

Programs are composable. If there already is a program that solves your problem, you can interface with that in various ways* and don't need to solve the same problem again. Thus Visual Studio Code can offer compilation, but not have its own compiler -- because it uses an already-existing one.

* E.g., CLI (invoking a compiler), static or dynamic linking (with DLL files), network (like with the LSP), and web requests (against an API).

1

If you want to understand this subject more, the keyword is 'parsing'. I'm not going to get into all the technical details of this but, informally, these editors are checking the text against a 'grammar'. This grammar defines how text is grouped together and what sequences of text/groupings are allowed. The process of parsing is the first portion of what compilers do. Once that is complete, if the text supplied is valid, the compiler then generates something that a computer can execute based on the rules of the language.

Essentially these editors are doing the first portion: grouping the text and checking its validity at a language-level but they don't continue on to the next step. A lot of IDEs also separate these two components and don't necessarily compile the code every time it's checked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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