1 / 17

Issues in Language Design

By N S Kumar kumaradhara@gmail,com. Issues in Language Design. Before we start. * To err is human To criticize is our right * what is in the name? Rose by any other name. Before we start. Prostrations to the greats : Backus McCarthy Wirth Ritchie Stroustrup Gosling Wall

omarquez
Download Presentation

Issues in Language Design

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. By N S Kumar kumaradhara@gmail,com Issues in Language Design

  2. Before we start ... * To err is human To criticize is our right * what is in the name? Rose by any other name ...

  3. Before we start ... • Prostrations to the greats : • Backus • McCarthy • Wirth • Ritchie • Stroustrup • Gosling • Wall • Rossum • ...

  4. What we plan discuss • Language features • From the programmer perspective • From the translator(compiler, linker, loader) perspective

  5. Should a language violate the law of least expectation? • Perl : • print (2 + 2) * 5; # 4 • Python 2.x • 5 < “10” => True • 15 < “10” => True • Fortran : • DO I 100 = 1.5 // NO LOOP !! • <stmt> ... • 100 CONTINUE

  6. Should a language have lexical ambiguity? * comma : separator or operator 'C' : printf(“%d”, 10, 20); printf(“%d”, (10, 20)); PL/I : = : assignment or relation ? Parentheses : semantics ?

  7. Should we be consistent in use of symbols? Java: for(e1; e2; e3) <stmt> | <block> Comma operator allowed in e1 and e3 And nowhere else in the program String class overloads + operator; we cannot!!

  8. How do we understand semantics of these expressions? - a = 10; ++ ++ a; // ok in C++ a ++ ++; // error in all langauges !! - a = a + b same as a += b ? Perl: @a = (11, 22, 33, 44); @a = @a + 10 ; // @a = (14) @a = (11, 22, 33, 44); @a += 10; # syntax error

  9. How do we understand semantics of these expressions? * a - - - b // C, C++, Java void foo(char *= “fool”); // C++ “I am “ “a fool “ // C, C++, Python template<typename C = vector<int>> // C++ Class { … };

  10. How do we understand semantics of these expressions? Python: def f1(x) : x = [33, 44] a = [11, 22] ; f1(a) def f2(x) : x += [33, 44] a = [11, 22] ; f1(a) def f1(x) : x = x + [33, 44] a = [11, 22] ; f1(a)

  11. Key words or none * lots of keywords Cobol => 420 keywords(!) * no keyword PL/I If if = then then then = 111; else else = 222; * overload keyword : static virtual * contexual keyword: C++ void foo() override; void operator=(...) = default;

  12. Can a compiler generate multiple destructors for a class? class A { public: virtual ~A() { } }; class B : virtual class A{ public: ~B() { } }; class C : virtual class A{ public: ~C() { } }; Class D : public B, public C { } B b; D d; // what happens?

  13. How to have templates in multiple translations? File.h : template<typename T> T sq(T x); File.cpp : template<typename T> T sq(T x) { return x * x; } Client.cpp : int a = sq(10); int b = sq(1.1); g++ -c File.cpp g++ -c Client.cpp G++ File.o Client.o Linker error !!! What if we export the declaration?

  14. What does linker to if a function is instantiated more than once in different translations? File1.cpp template<typename T> T sq(T x) { return x * x; } a = sq(11); b = sq(1.1); File2.cpp template<typename T> T sq(T x) { return x * x; } c = sq(22); b = sq(1.1f); Linker gets two instances of T = int !!

  15. How do we walk through an iterable? - enhanced for loop: java - range for: C++ - for : python - foreach : perl Loop for reading and modifying an array Loop for reading and modifying a string Loop for reading and modifying a user defined container

  16. What are these? * marker interface * monkey patching * duck typing * hoisting * try with resource * callable * iterable * concept * move semantics

  17. Any questions?

More Related