170 likes | 189 Views
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
E N D
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 • Rossum • ...
What we plan discuss • Language features • From the programmer perspective • From the translator(compiler, linker, loader) perspective
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
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 ?
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!!
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
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 { … };
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)
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;
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?
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?
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 !!
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
What are these? * marker interface * monkey patching * duck typing * hoisting * try with resource * callable * iterable * concept * move semantics