D Programming Language

Similar documents
CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010

CSE 303: Concepts and Tools for Software Development

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 19 Introduction to C++

Software Design and Analysis for Engineers

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

Introduction to Programming Using Java (98-388)

COSC 2P95. Procedural Abstraction. Week 3. Brock University. Brock University (Week 3) Procedural Abstraction 1 / 26

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Operating Systems CMPSCI 377, Lec 2 Intro to C/C++ Prashant Shenoy University of Massachusetts Amherst

Chapter 1 Getting Started

Lecture 10 Notes Linked Lists

JAVA An overview for C++ programmers

Lecture 10 Notes Linked Lists

CS558 Programming Languages Winter 2018 Lecture 4a. Andrew Tolmach Portland State University

CS558 Programming Languages

Grafting Functional Support on Top of an Imperative Language

1B1b Inheritance. Inheritance. Agenda. Subclass and Superclass. Superclass. Generalisation & Specialisation. Shapes and Squares. 1B1b Lecture Slides

QUIZ on Ch.5. Why is it sometimes not a good idea to place the private part of the interface in a header file?

A brief introduction to C programming for Java programmers

JAVA: A Primer. By: Amrita Rajagopal

Lecture Notes on Queues

Chapter 6 Introduction to Defining Classes

Chapter 5. Names, Bindings, and Scopes

Short Notes of CS201

Hacking in C. Pointers. Radboud University, Nijmegen, The Netherlands. Spring 2019

Hierarchical inheritance: Contains one base class and multiple derived classes of the same base class.

Object Oriented Programming. Solved MCQs - Part 2

Lecture Notes on Memory Layout

CS201 - Introduction to Programming Glossary By

OpenACC Course. Office Hour #2 Q&A

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

Rules and syntax for inheritance. The boring stuff

Interview Questions of C++

Data Abstraction. Hwansoo Han

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline

Midterm 2. 7] Explain in your own words the concept of a handle class and how it s implemented in C++: What s wrong with this answer?

CS Internet programming Unit- I Part - A 1 Define Java. 2. What is a Class? 3. What is an Object? 4. What is an Instance?

The Dynamic Typing Interlude

CSE 307: Principles of Programming Languages

CPS 506 Comparative Programming Languages. Programming Language


Design Issues. Subroutines and Control Abstraction. Subroutines and Control Abstraction. CSC 4101: Programming Languages 1. Textbook, Chapter 8

What are the characteristics of Object Oriented programming language?

Qualifying Exam in Programming Languages and Compilers

Sharing Objects Ch. 3

Ch. 11: References & the Copy-Constructor. - continued -

Lecture Notes on Programming Languages

Principles of Programming Languages. Objective-C. Joris Kluivers

2.4 Structuring programs

Lecture 6 Introduction to Objects and Classes

QUIZ Friends class Y;

Design Principles for a Beginning Programming Language

QUIZ. What is wrong with this code that uses default arguments?

C++ Important Questions with Answers

CPSC 3740 Programming Languages University of Lethbridge. Data Types

CS 31: Intro to Systems Pointers and Memory. Kevin Webb Swarthmore College October 2, 2018

CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING C ++ Basics Review part 2 Auto pointer, templates, STL algorithms

Cpt S 122 Data Structures. Introduction to C++ Part II

1/29/2011 AUTO POINTER (AUTO_PTR) INTERMEDIATE SOFTWARE DESIGN SPRING delete ptr might not happen memory leak!

These are notes for the third lecture; if statements and loops.

Java Threads and intrinsic locks

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011

A student was asked to point out interface elements in this code: Answer: cout. What is wrong?

Casting -Allows a narrowing assignment by asking the Java compiler to "trust us"

Objects and Classes. Amirishetty Anjan Kumar. November 27, Computer Science and Engineering Indian Institue of Technology Bombay

Object Oriented Programming. Assistant Lecture Omar Al Khayat 2 nd Year

Exception Namespaces C Interoperability Templates. More C++ David Chisnall. March 17, 2011

RAJIV GANDHI COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF INFORMATION TECHNOLOGY OBJECT ORIENTED PROGRAMMING QUESTION BANK UNIT I 2 MARKS

inside: THE MAGAZINE OF USENIX & SAGE August 2003 volume 28 number 4 PROGRAMMING McCluskey: Working with C# Classes

Inheritance: Develop solutions by abstracting real-world object and their interaction into code to develop software solutions. Layering: Organization

Item 4: Extensible Templates: Via Inheritance or Traits?

C++ for Java Programmers

CS3157: Advanced Programming. Outline

Kakadu and Java. David Taubman, UNSW June 3, 2003

Chapter 10 :: Data Abstraction and Object Orientation

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

More C++ : Vectors, Classes, Inheritance, Templates. with content from cplusplus.com, codeguru.com

However, in C we can group related variables together into something called a struct.

Pointers and Memory 1

Ch. 12: Operator Overloading

September 10,

CS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 11

PIC 10A Objects/Classes

EMBEDDED SYSTEMS PROGRAMMING More About Languages

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

Implementing Interfaces. Marwan Burelle. July 20, 2012

Programming Exercise 14: Inheritance and Polymorphism

7. C++ Class and Object

class objects instances Fields Constructors Methods static

Advances in Programming Languages: Regions

Subprograms. Bilkent University. CS315 Programming Languages Pinar Duygulu

Unix System Programming - Chapter 2, part a

Reading Assignment. Lazy Evaluation

Ch. 10: Name Control

Object-Oriented Programming

Lecture Notes on Queues

+ Abstract Data Types

Pointers and References

Introduction to the D programming language. Marc Fuentes - SED

Transcription:

Group 14 Muazam Ali Anil Ozdemir D Programming Language

Introduction and Why D? It doesn t come with a religion this is written somewhere along the overview of D programming language. If you actually take the time to look how things are done in D you can see this line tells a lot for this programming language such that, it is multi paradigm so that it s aim is to take good features of every paradigm. So you don t have to choose one in D. You can use imperative, object oriented, generic and even functional paradigms. The main objective is written as practical language for practical programmers who need to get the job done quickly, reliably, and leave behind maintainable, easy to understand code. One can easily notice that D is trying to make it easier on programmer as much as possible with intuitive approaches to features taken from many other paradigms. So whatever you want to do and however you want to do, D aims to let you do it without getting your way too much while trying to minimize common mistakes as much as possible. These terms might seem a bit unclear and too idealistic at first but D argues that convenience and efficiency are not necessarily mutually exclusive. For example in D all variables are initialized unless you don t want them to ( via void ), array usage is intuitive and easy, overloading is simple, iteration is clean,you can use NaN etc. When we are talking about new languages it is usually the case that we start by comparisons with an existing language. D is mostly established over C/C++ to the point that entire C is available without any interface, however D argues that you would never need to do so because of D s own features that are more powerful, safer and efficient. One of the goals of D is listed as Where D code looks the same as C code, have it either behave the same or issue an error. [1] However while doing this it is also argued that C++ while being powerful and efficient is also being held back by the necessity of being compatible with C. So the question becomes can we become, while being powerful and efficient like C++ and also keep it simple and practical to use. There are many design goals for D however the most important point of them all would be listed as Whenever a conflict in design happens, resolution will be in favor of usability. Object Oriented D You have structs and classes in D, structs are meant for value types and classes are for encapsulation, inheritance, polymorphism. Every class has its root as class Object. Multiple inheritance is not supported due to the problems and complexity it brings isn t really worth instead Java style interfaces. Classes has lots of flexibility, you can access them and their fields( values) in many ways, in contrast to C++ you can define classes and function in the same file, where in C++ you have to make a header and an implementation file redefining the same functions. These approaches lines pretty good with the goals we mentioned before, keeping the power and also making it simple to use and not having a hard time for coder. One feature is to access in terms of byte with keyword offset another is to access the fields ( excluding the hidden ones ) by tupleof keyword.

Functional D D supports immutability as well, you can define a data immutable so it will never ever change. However we still don t want to give up the conventional functionality that comes with mutation, so D tries to combine them both in a smooth way. This sets the foundation of true parallel programming as in D if you are in immutable territory you have the guarantee that correctly typed program can t change immutable data. Also it works such that if you are in immutable territory and follow a reference, you are guaranteed to end up in immutable territory. We mentioned parallel programming before so why immutable data is awesome, it is because in terms of synchronization. It is usually the case(in other programming languages) that system doesn t know which data should be shared and which isn t so the burden is always on programmer however D says that every memory is private unless specified as shared. So with shared qualifier data will be visible to multiple threads at once. System therefore knows which data is shared and which is not and can take proper steps for synchronization. Now combined with immutable data, we can say the best synchronization is no synchronization since sharing immutable data around needs no such thing as synchronization. These all come together in D as long as the immutability holds. [2] SafeD World One interesting area of D programming language is the SafeD where there is no possible way to have a memory corruption. Are you sick of dealing with C s way of handling pointers or counting mallocs/free s. D offers a world for you to safely and securely write your code without dealing with any of those. When you enter SafeD you leave pointers unchecked casts behind. The most important promise would be your code if compiles, it most of the time works, which of course also depends on your definition of work but the point is there is no undefined behaviours. Where like in C issue with dangling pointers and such as you can guess can and will result in undefined behaviour if dereferenced. Garbage Collection in D Considering the approach D has with all other things it shouldn t be hard to guess which way they took in garbage collection. You don t have to deal with garbage collection in D by default just allocate and later on garbage collector will return all unused memory however you still have the flexibility to specify where you don t want garbage collector get involved. There are basically two types of pointers in D those who reference to garbage collected memory and those do not which is basically C type of pointers so for these anything you can do in C is also legal in D. However there are still some restrictions such that you can t cast them etc. to keep the flexibility of garbage collector design.

Error Handling Error handling in D is quite straightforward but before going into that lets look at other languages way of handling like C. C way of handling errors, detecting and reporting them isn t really consistent and varies. So basically to deal with each situation(error) there needs to be a code for detecting and reporting as well. Eventually as it builds up this error handling code can even get error prone as well. D s way of handling errors starts with some assumptions that basically states that errors are not planned part of the program which means they are exceptions and unexpected hence the error handling code does not have to be performance critical. All errors are objects that are derived from Error class where it contains a function tostring which produces a text for human to read. It is quite straightforward in the sense that if the error is out of memory then it displays Out of Memory so as we mentioned even if this process, exception handling stack unwinding is a relatively slow, we don t really care since we know it is not the normal flow of the program it is an error. Since normal flow does not have to check for errors for every function, it can be realistically faster to use exception handling for errors. Templates/Generic Programming in D Templates in D is quite similar to C++ however there are few differences and added features I would say to make it more flexible or more expressive. One example is a template instantiation can be aliased such that : Example taken from http://dlang.org/: template TFoo(T) { alias t = T*; } alias abc = TFoo!( int ); abc.t x; // declare x to be of type int Template arguments can be implicitly converted and will refer to the same type so that TFoo!(3) will be equal to TFoo!(3u) since 3u will be converted to 3 to match int. Alias parameters enable templates to be parameterized with and type of global name, local name, module name etc. So it offers quite a lot flexibility. You can also use nested templates and recursive templates. In General In overall we can pretty much say D tries to add to the functionalities and practicality of C++ by the lessons learned from its practical usage. It implements design by contract, lazy evaluation and compile time execution and has redefined template syntax. It still has C s ability

to do low level stuff however also offers lots of functionality so that you wouldn t normally need them. Improves string manipulation of C/C++ by improving array handling. However there are still areas where D comes short, firstly comes to mind is lack of tools support. Also I would see D as a still growing and adapting language as it has many paradigms and tries to keep better features of them all so it is not by any sense a complete language. Even if it is compared mostly to C and really comparable to C, D is not for legacy since it needs modifications to the C code to run. Sources: [1] : http://dlang.org/overview.html [2] :The Case for D Andrei Alexandrescu http://www.drdobbs.com/parallel/the case for d/217801225?pgno=2 [3] : http://wiki.dlang.org/