Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5....

56
Comparing and Contrasting C#, Scheme, and T-SQL Joseph P. Mohr

Transcript of Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5....

Page 1: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Comparing and Contrasting C#, Scheme,

and T-SQLJoseph P. Mohr

Page 2: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

1. C# Overview2. Scheme Overview3. T-SQL Overview4. Language Comparisons5. Conclusions

Outline

Page 3: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Object-Oriented Language Type-Safe Evolved from C Main application is server-side scripting in

the .NET Framework Developed in 2001 Current version is 4.0

C# Overview

Page 4: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

C# is designed for component-oriented programming

Software Components◦ Increasingly used in modern software design◦ Self-contained and self-describing◦ Have their own documentation

C# Advantages

Page 5: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Versioning◦ Allows the language to evolve without breaking

programs in older versions.◦ Supports virtual and override modifiers. ◦ Method overloading that supports versioning.◦ Explicit interface member declarations.

C# Advantages

Page 6: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Virtual and Override◦ If a method is declared virtual, then the

implementation evokes is determined at run-time.◦ Non-Virtual methods have the implementation

determined at compile-time.◦ The override modifier can be used to provide

another implementation for an existing virtual method.

C# Advantages

Page 7: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

C# programs are comprised of the following:◦ Programs◦ Namespaces◦ Types◦ Members◦ Assemblies

C# Program Structure

Page 8: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Consist of one or more source files Source files contain the other structural

elements of the program

C# Programs

Page 9: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Declared at the top of the source file with the using directive

Avoid having to use the fully qualified names in the source code.

C# Namespaces

Page 10: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Most common types:◦ Classes◦ Interfaces

Can contain members and namespaces Either reference or value With reference type, two variables can

affect the same object.

C# Types

Page 11: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Most common members:◦ Fields◦ Methods◦ Properties◦ Events

C# Members

Page 12: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Made up of Intermediate Language (IL) and metadata

Use Just-In-Time (JIT) compiling Implement applications or libraries and

have the .exe or .dll file extension respectively

C# Assemblies

Page 13: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Using System;Class Hello{

Static void Main() {Console.Out.WriteLine(“Hello, World”);

}

}

C# Hello World Program

Page 14: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

C# uses two different grammars, the Lexical grammar and the syntactic grammar.

Lexical grammar defines line terminators, white space, comments, tokens, and preprocessing directives.

Syntactic grammar defines how the tokens from the lexical grammar are combined into programs.

C# Grammars

Page 15: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Compiled language results in fast execution. High performance is a result of being

derived from the C family. Boxing and Unboxing operations are the

most common detriments to performance.◦ Can be avoided by declaring as Object

C# Performance

Page 16: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Pros:◦ Clearly defined data types◦ Familiar, well designed syntax

Cons:◦ Feature multiplicity◦ Operator Overloading

C# Readability

Page 17: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Pros:◦ Excellent support for abstraction◦ Strong expressivity with control sections

Cons:◦ Large number of different contstructs

C# Writability

Page 18: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Classes derived from the base Object Class, which includes implementation of the primitives, can be simply combined to create very robust and diverse data structures.

C# Orthogonality

Page 19: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Type-Checking:◦ C# is considered a type-safe language and the

compiler can catch type errors in almost all cases.◦ There are pointers supported by the language

which can prevent the compiler from catching type-errors.

Exception Handling:◦ Highly functional and similar to Java

C# Reliability Pros

Page 20: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Aliasing:◦ Reference types can be referring to the same

memory location and is considered a detriment to reliability.

C# Reliability Cons

Page 21: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

The modular design considerations of C# makes the code highly portable.

Self-contained documentation in all the modules makes for easier portability amongst different software developers.

C# Portability

Page 22: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

MS Visual C# MS Visual Studio

C# Tools and Compilers

Page 23: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;

namespace WebApplication2{ public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) {

} protected void Calendar1_DayRender(object sender, DayRenderEventArgs e) { EventDataContext edc = new EventDataContext();

var query = from ev in edc.Events where ev.Date == e.Day.Date select ev;

C# Personal Example

Page 24: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

e.Cell.VerticalAlign = VerticalAlign.Top; e.Cell.BorderColor = System.Drawing.Color.Teal; e.Cell.BorderWidth = 1; e.Cell.BorderStyle = BorderStyle.Solid;

foreach (var ev in query) { HyperLink link = new HyperLink(); link.ForeColor = System.Drawing.Color.Teal; link.NavigateUrl = "~/EventInfo.aspx?event=" + ev.EventNo; link.Text = ev.Name; Button but = new Button(); e.Cell.Controls.Add(new LiteralControl("<p>")); e.Cell.Controls.Add(link); e.Cell.Controls.Add(new LiteralControl("</p>")); } } }}

C# Personal Example Contd.

Page 25: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

www.myjaxcalendar.com

C# Demo

Page 26: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Functional programming language Evolved from LISP Created in 1975 at MIT by Guy L. Steele and

Gerald J. Sussman Originally called Schemer to mimic the

naming convention used by other languages evolved from LISP, such as Conniver

Considerably more minimalist than Common Lisp, but supports tools for language extension.

Scheme Overview

Page 27: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Most commonly used for lambda calculus and as an educational tool by introductory level computer science classes.

Lambda calculus is a logical system of computation through the use of binding and substitution.

Scheme Applications

Page 28: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Scheme programs are interpreted. Program Elements:

◦ Keywords ◦ Variables◦ Structured forms ◦ Constant data (numbers, characters, strings,

quoted vectors, quoted lists, quoted symbols, etc.)

◦ Whitespace◦ Comments

Program expressions are known as s-expressions

Scheme Programs

Page 29: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

S-expressions are made up of structured forms and lists.

S-expressions are delineated by matching sets of opening and closing parentheses.

Scheme Syntax

Page 30: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

List-processing primitives:◦ car – the first element in a list◦ cdr – all the other elements in the list◦ cons – constructs lists

First-class functions (functions can be assigned to variables)

Scheme Primitives and Variables

Page 31: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Only the inner-most binding of a variable is visible in an expression.

Inner bindings are said to “shadow” the outer bindings.

This type of scoping is known as “lexical scoping”.

Scheme Variable Scoping

Page 32: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Expression:◦ (cdr (car ‘((1 2 3) 4 5)))

Result:◦ (2 3)

Scheme Example Expression

Page 33: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Scheme executes faster and more efficiently than Common LISP as a result of its minimalist design.

Scheme Performance

Page 34: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Pros:◦ Overall Simplicity of the language, including a

lack of feature multiplicity, improves the readability of the language.

◦ Identifiers are not restricted in length. Cons:

◦ The dynamic variable types which aren’t explicitly declared to be of a certain data type.

Scheme Readability

Page 35: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Pros:◦ The overall simplicity of the language, especially

over that of Common LISP Cons:

◦ Weak support for abstraction◦ Lacking expressivity

Scheme Writability

Page 36: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Simply supports the most commonly used data structures including Strings and Enums.

Lacking in the ability to combine primitives in to complex data structures.

Scheme Orthogonality

Page 37: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Pros:◦ Lack of aliasing◦ Performs run-time type checking

Cons:◦ Does not have a good system for exception

handling.

Scheme Reliability

Page 38: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Scheme programs are highly portable between the same version of Scheme.

The very high number of versions of Scheme in use is major stumbling block to the portability of Scheme.

Scheme Portability

Page 39: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Some of the many flavors of scheme are:◦ SISC – runs off of the JVM◦ DrRacket – Student friendly interface◦ MIT Scheme – very widely used

Scheme Flavors

Page 40: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Scheme Demo

Page 41: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Query Language Uses statements that are interpreted by the

database server. Used with relational databases

◦ Relational databases are based off of first order predicate logic.

Used by MS SQL Server database and Sybase database.

Main application is the construction and manipulation of enterprise databases.

T-SQL Overview

Page 42: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

History:◦ Evolved from SEQUEL.◦ SEQUEL (Structured English Query Language) is a

query language developed by IBM in the 1970’s and they later renamed it to SQL (Structured Query Language)

◦ T-SQL (Transact SQL) is an extension to SQL developed by a partnership between Microsoft and Sybase.

T-SQL Overview

Page 43: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Data in relational databases are comprised of entity types

Entity Types are collections of the of the entities and thought type and are represented as TABLES.

Each instance of that entity is a record or tuple and is represented as a row in the table.

Records are comprised of different attributes, and they are represented as columns in the table.

T-SQL Overview

Page 44: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

T-SQL is technically a data-sublanguage The T-SQL sublanguage is comprised of the

following:◦ Data Definition Language (DDL)◦ Data Manipulation Language (DML)

T-SQL Overview

Page 45: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

The DML is used to define database structure, integrity rules, and user privileges.

Includes the following commands:◦ CREATE TABLE, DROP TABLE, ALTER TABLE◦ CREATE VIEW, DROP VIEW◦ CREATE INDEX, DROP INDEX

T-SQL DML

Page 46: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

The DML is used to manipulate the data within the database.

DML Commands Include:◦ SELECT◦ INSERT◦ UPDATE◦ DELETE

T-SQL DML

Page 47: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

T-SQL extends SQL to include:◦ Procedural Programming◦ Local Variables◦ Support functions for processing various data

types The extensions included in T-SQL grant it

equivalent capabilities to other programming languages.

T-SQL Extensions

Page 48: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Flow control in T-SQL:◦ Begin◦ End◦ Break◦ Continue◦ GOTO◦ IF◦ ELSE◦ RETURN◦ WHILE◦ WAITFOR

T-SQL Extensions

Page 49: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

T-SQL contains try-catch blocks, unlike SQL Example:

BEGIN TRY//STATEMENTS

END TRYBEGIN CATCH

//STATEMENTS TO HANDLE EXCEPTIONEND CATCH

T-SQL Exception Handling

Page 50: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

T-SQL Demo

Page 51: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

T-SQL performs queries and data manipulation very efficiently across a wide variety of data types.

T-SQL Efficiency

Page 52: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Readability:◦ High overall simplicity. Lack of multiplicity and

overloading.◦ Excellent facilities for defining data types◦ Form indicates meaning

Writability:◦ More expressive than SQL◦ Poor Abstraction

T-SQL Simplicity

Page 53: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

T-SQL supports a wide variety of primitive data types

The primitive data types can be easily combined in tables to easily create new data structures.

T-SQL Orthogonality

Page 54: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Type-Checking:◦ Data must be of the appropriate type for a

statement to execute. Exception-Handling:

◦ T-SQL provides for exception handling, unlike SQL.

T-SQL Reliability

Page 55: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

Modularity and portability are a common and touted attribute amongst the languages, but C# achieves this goal to a greater extent than the others.

C# does not support shadowing like Scheme does.

All three languages are supported cross-platform.

Language Comparisons

Page 56: Joseph P. Mohr. 1. C# Overview 2. Scheme Overview 3. T-SQL Overview 4. Language Comparisons 5. Conclusions.

I drew the following conclusions my research in to these three languages:◦ Studying different types of languages increased

my ability to select an appropriate language for a given task.

◦ As I learned more languages, I was able to pick up new languages faster.

◦ Due to the similarities between the languages, studying C# improved my knowledge of Java.

◦ Many projects are best implemented through the use of multiple languages.

Concluding Remarks