Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Library vs Language extension

What is the difference between a Library and a Language extension? Specifically in Scala.

like image 602
Nabegh Avatar asked May 07 '12 07:05

Nabegh


People also ask

What is a language extension?

An extension language is a programming language interpreter offered by an application program, so that users can write macros or even full-fledged programs to extend the original application.

What is a language library?

The purpose of the Language Library is to translate any string value (text) to another language. There are very specific use cases for the Language Library. you may need to change the captions of some build-in labels to something suitable to your organization.

Which programming language has more library?

C++ is much efficient compare to most of programming languages. Many powerful libraries such as TensorFlow and Torch are implemented in the C++ programming language so machine learning and C++ is truly a great combination.

What is a function of library WRT higher level programming languages?

In programming, a library is a collection of precompiled routines that a program can use. The routines, sometimes called modules, are stored in object format. Libraries are particularly useful for storing frequently used routines because you do not need to explicitly link them to every program that uses them.


2 Answers

This is the Scala language specification. If you can write it with the language described by this specification, then it is a library. If you make changes to the language described by this document that cannot be written in the language itself, then it is a language extension.

like image 67
Dan Burton Avatar answered Sep 28 '22 08:09

Dan Burton


This is valid both for Scala and for Java, a library could be defined as:

In computer science, a library is a collection of resources used to develop software. These may include pre-written code and subroutines, classes, values or type specifications.

It means that (I know, I simplify a lot) a library is a collection of routines you'll use in your code to implement an algorithm. They save you to write the same code again and again (for example you do not need to reinvent the wheel every time you have to print a string to console).

A language extension is not code that you'll call (or use) directly from your code but something that will change how you write your programs. It may change (and usually it does) the syntax of the language itself and often it's a plug-in for the compiler. Many of the features added to the Java language are extension (generics, for example).

For example Session-Scala is an extensions made of both:

  • a library to manage parallel programming (code you can call directly from your code).
  • a language extension: to make the code you write more clear (what sometimes is called syntactic sugar), it changes the syntax of the language to make the use of its library functions more easy (should I say nice?)

For an example take a look to this page.

That said, often with Scala a language extension isn't really needed (even if it's so easy to write, more than for .NET languages, for example) because of its syntax. First thing that comes to my mind are infix operators but in general all its syntax for methods invocation makes everything simple to use it as DSL without a DSL.

like image 34
Adriano Repetti Avatar answered Sep 28 '22 09:09

Adriano Repetti