1 / 34

D Language

D Language . kasa study 이민우. Content. Features To Drap. What is D?. Who D is For. Why D?. Major Design Goals of D. Major Features of D. Features To Keep. Visual D. D with Game Programming. What is D?. purpose systems and application.

kaethe
Download Presentation

D Language

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. D Language kasa study 이민우

  2. Content Features To Drap What is D? Who D is For Why D? Major Design Goals of D Major Features of D Features To Keep Visual D D with Game Programming

  3. What is D? • purpose systems and application. • high level language, but interface directly osapi and hardware. • job done quickly, reliably, and leave behind maintainable, • easy to understand code. • draws inspiration from those other languages and • tempers it with experience and real world practicality. Walter Bright Andrei Alexandrescu

  4. What is D? C++ C# JAVA

  5. What is D? C++ C# JAVA

  6. Why D? • software industry has come a long way since • the c language was invented. • many new concepts were added -> c++. • compatibility with c was maintained. • -> weaknesses of the original design. • new features must be carefully fitted into the • exisiting structure without requiring rewriting old code. • -> very complicated.

  7. Why D? • cstandard: 500 pages • c++ standard: 750 pages • c++ implements things like resizable arrays and string concatenation • as part of the standard library. • In c++ - • const char abc[5] = "world"; • string str = "hello" + abc; • In d - • const char[5] abc = "world"; • char[] str = "hello" ~ abc; • D string vs C++ string

  8. Why D? c: 500 page c++ : 750 page Can the power and capability of c++ be extracted, Redesigned, and recast into a language that is Simple, Orthogonal, and practical?

  9. Major Design Goals of D • memory safe programming. • multi paradigm programming. • . imperative • . object oriented • . generic • short learning time for programmers. • provide low level bare metal access as required. • context free grammar. • incorporate contract programmig and unit testing methodology

  10. Features To Keep • look and feel of c/c++ • c style function-and data or c++ style object-oriented, • template metaprogramming, or mix. • compile/link/debug. • operator overloading. • Runtime Type Identification. • maintains function link compatibility with the C calling conventions. • Template Metaprogramming. • RAII • Down and dirty programming

  11. Features To Drop • c source code compatibility. • link compatibility with c++. • c perprocessor. • multiple inheritance. • name space. • forward declarations. • include files • support for 16 bit computers. • mutual dependance of compiler passes. • compiler complexity. • template overloading of < and > symbols.

  12. Who D is For • eliminate bugs before the code is even compiled. • people who compile with maximum warring levels. • enjoy c++, but are frustrated by the need to expend • much effort explicitly managing memory and finding pointer bugs. • should provide enough features to obviate the continual • necessity to manipulate pointers directly. • Numerical programmers. • half their application in scripting languages like Ruby and Python, • and the other half in c++ to speed up the bottlenecks.

  13. Major Features of D Object Oriented Prograpping Productivity Functional Array Resource Management Performance Reliability Project Management

  14. Object Oriented Programming - class class A { this () { foo (); } class B : A { this () { super (); } int main ( char [] [] args ) { A a = new A (); // writes "foo from A" B b = new B (); // writes "foo from B" return 1; }

  15. Productiviy - modules In c++ #paragma … #ifndef … #endif In D import Lookup; import std.stdio; import std.string;

  16. Productiviy – declaration vs definition C++ : int ABC::func() { return 7; } int ABC::z = 7; extern int q; D : class ABC { intfunc() { return 7; } static int z = 7; } int q; D : class Foo { intfoo(Bar c) { return c.bar; } } class Bar { int bar() { return 3; } } C++ : class Foo { intfoo(Bar *c){ return c->bar(); } }; class Bar { public: int bar() { return 3; } };

  17. Productiviy – template template factorial(T) { T factorial(T n) { if (n <= 1) return cast(T)1; else return cast(T)( n * factorial(n-1)); } } int main ( char [] [] args ) { for(inti=0; i<8; i++) writefln("%s! = %s", i, factorial(i)); return 1; }

  18. Productiviy – associative array char[][char[]] aA; printf("Fill in the array.\n"); aA["a"] = "Apple"; aA["b"] = "Book"; aA["c"] = "Car"; C++ implements asociative array as part of Standard library, not as part of the core language.

  19. Function – nested function Inc++ void outer() { static int v1 = 5; int v2 = 5; struct thru { static void inner() { std::cout << v1 << std::endl; //std::cout<<v2<<std::endl; } }; thru::inner(); } InD intaddSquares(int a, int b) { intsquareIt() { return (a * a) + (b * b); } return squareIt(); }

  20. Array • C arrays have serveral faults : • when an array is passed to function, • all array type information gets lost. • c arrays connot be resized. • c array cannot be bounds checked. • arrays are declared with the []after the identifier. • -> int (*array)[3]; • in D. the [] for the array go on the left. • -> int[3]* array; long[]func(int x);

  21. Resource Management • D memory allocation is fully garbage colected. • -> language gets much simpler. • eliminates the tedious, error prone memory allocation tracking code • -> much faster development time, lower maintenance costs. • garbage collectors can be used with c++. • -> impeding the effectiveness of it. • -> much of the runtime library code can’t be used with collectors. • D support RAII in a controlled, predictable manager that is • independent of the garbage collection cycle.

  22. Performance – inline assembler void main() { intlen; uintzCode; … asm { cld; movECX,len; movEAX,zCode; movEDI,pss; repne; scasb; movEBX,len; sub EBX,ECX; dec EBX; movfoundOffset,EBX; } }

  23. Relibility – contract programming • DbC(Design by Contract) • double sqrt( double x) • // Precondition • in { assert( x >= 0); } • // Postcondition • out(result) { assert( result >= 0 && approxEqual(result * result, x) ); } • body { • // sqrt implementation • double y; • . . . • return y; • }

  24. Relibility – unit test • unit tests can be addded to a class, such they are • automatically run upon program startup. • void main() • {} • class Foo • { int x, y; } • unittest • { • Foofoo = new Foo; • foo.x = 2; • foo.y = 4; • assert(foo.x != foo.y, "this assert passes"); • assert(foo.x < foo.y); • }

  25. Relibility • synchronization ( D provides primitives to build multithreaded program ) • -> synchronized intfunc(){…} • support for robust techniques • -> dynamic arrays instead of pointers. • -> reference variables instead of pointers. • -> reference objects instead of pointers. • -> garbage collection instead of explicit memory management. • -> built in primitives for thread synchronization. • -> no macros to inadvertently slam code. • -> inline functions instead of macros. • -> vastly reduced need for pointers. • -> no more uncertainty about the singed-ness of chars. • -> no need to duplicate declarations in source and header files.

  26. Relibility - check • compile time check • -> stronger type checking. • -> no empty ; for loop bodies. • - runtime checking • -> assert() expressions. • -> array bounds checking. • -> undefined case in switch exception. • -> out of memory exception. • -> in, out, and class invariant Contract Programming support.

  27. Project Management - versioning version(XX) { // code here gets compiled if version XX is active } version(2) { // code here only gets compiled if the version has been // set to 2 or higher. } version(none) { // this code is now commented out }

  28. Visual D

  29. Game Programming?

  30. ICFP Programming Contest

  31. 2007

  32. 2010

More Related