• No results found

INF 6 Programming Environments and dotNET Technology

N/A
N/A
Protected

Academic year: 2020

Share "INF 6 Programming Environments and dotNET Technology"

Copied!
35
0
0

Loading.... (view fulltext now)

Full text

(1)

Programming Environments. .NET Technology

Subjects:

-How computer runs a program

-How programs are converted into machine language that a program can

understand

-What features typically are included in a development environment

-What features the Microsoft Visual Studio development environment

provides

-.NET Solution

-Building Blocks of the .NET Platform

-Common Language Runtime

-.NET Assemblies

-The Role of .NET Type Metadata

-Just-in-time compiling

(2)

Introduction

In theory, you could write computer programs using any text editor, but in practice, that would be difficult. Programming languages are extremely picky, so one missing or misplaced character can make a program useless.

To make it easier to write programs that are at least syntactically correct, programming languages typically come with programming environments that include tools to help you design, write, run, test, and debug programs.

BASIC TERMS

A computer program (or just a program) is a sequence of instructions written to perform a specified task with a computer. A computer requires programs to function, typically executing the program's instructions in a central processor. The program has an executable form that the computer can use directly to execute the instructions.

(3)

BASIC TERMS

In computer science, source code is any collection of computer instructions (possibly with comments) written using some human-readable computer language, usually as text. The source code is automatically translated at some point to machine code that the computer can directly read and execute.

Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a computer program or a piece of electronic hardware, thus making it behave as expected.

A compiler is a computer program (or set of programs) that transforms source code written in a programming language (the source language) into another computer language (the target language, often having a binary form known as object code). The most common reason for wanting to transform source code is to create an executable program.

(4)

From Software to Hardware

People transfer information using spoken and written languages such as English, Spanish, etc. The computer’s processor is very different. It reads a series of 0s and 1s and produces a new series of 0s and 1s.

For example, the following machine code tells an x86/IA-32 processor to copy the value

01100001 into the AL register (a special memory location for values that the process will later manipulate):

1011000001100001

Because this machine code is largely incomprehensible to humans, programmers write programs in higher-level programming languages. Later, another program converts the high-level program into machine code.

Assembly language is a low-level language that uses mnemonics to make machine language more readable. For example, the following assembly statement is equivalent to the previous machine code:

MOV AL, 61h ; Copy the value 61h into AL.

(5)

From Software to Hardware

(6)

From Software to Hardware

Some languages, such as Java, C#, and Microsoft Visual Basic, insert another step in the translation process to make programs more portable.

Instead of compiling directly to machine code, these languages’ compilers convert the high-level code into an intermediate language sometimes called bytecode.

Then, at run time, the intermediate code is compiled into machine code for execution. This step from intermediate code to machine code occurs at the last instant before the code is executed, so it is called Just-In-Time (JIT) compilation.

For Microsoft.NET-compatible languages, such as C# and Visual Basic, the intermediate representation is called Common Intermediate Language (CIL), and the run-time component that converts it into machine language is called Common Language Runtime (CLR).

In Java, the intermediate language is called Java bytecode, and the run-time component that converts it into machine language is the Java Virtual Machine (JVM).

(7)
(8)

Programming Environments

To make writing and debugging programs easier, programming environments include several useful tools. Some of the tools that a given programming environment might include are:

Code editor A special-purpose text editor that helps you create working code. Typical special features of code editors include automatic text coloring to differentiate kinds of code (such as variables, keywords, literal values, and comments), parenthesis matching (so you can easily see find an open parenthesis’ matching closing parenthesis, and vice versa), and syntax error highlighting.

Debugger Often integrated with the code editor, the debugger lets you step through the program one statement at a time to see what it does while running. Debuggers usually let you stop the program at a particular line of code, follow execution from one piece of code to another, and examine and change variable values. Some even let you change the program code and continue running the program from that point.

(9)

Programming Environments

Build automation tools These tools allow you to customize compilation. For example, a tool might notice that a particular module has been modified, recompile it, and then recompile any other modules that rely on that one so they are all up to date.

Testing tools These tools let you automatically perform a series of tests on a program to see if a feature works or to see if recent changes to the code have broken existing features (regression testing). Reports tell you if the program failed any of the tests.

Source code management tools These tools track changes to the source code and keep the code in a safe repository. Many of these tools allow you to compare two versions of the code to see what has changed.

Object-oriented tools These tools make it easier to understand how classes relate to each other. They may include a class browser, an object inspector, and a class hierarchy editor.

(10)

Visual Studio

Visual Studio is an IDE available from Microsoft. Visual Studio provides support for several languages, including C#, Visual Basic, C/C++, and F#. Although it is possible to write and compile programs in those languages without Visual Studio.

Visual Studio provides support for building console applications (those that read and write text from a simple text window), Microsoft Windows services that run in the background even if no user is logged in, Windows Forms applications (similar to those you typically see on Windows systems), websites, web applications, and web services

(11)
(12)

Visual Studio

Some other specific features that the Visual Studio IDE provides include:

Customizable menus and toolbars You can rearrange, create, and hide these items easily. You can add and remove commands to make it easier to find the tools that you use the most. For example, if you often edit Extensible Markup Language (XML) data files, you can display the XML Editor toolbar to make editing those files easier. You can even add menu items and toolbar buttons to perform new actions such as opening a web page, sending email, or executing code that you have written.

Customizable windows You can decide which windows (code editors, toolbars, data views, and so forth) are visible and where they are positioned. You can make windows become tabs in a single window, give each window its own area, or make a window float above others.

(13)

Visual Studio

IntelliSense This is an auto-completion feature provided by the code editor. If you type part of the name of a variable, function, or other program symbol, IntelliSense lists the symbols that might match your choice. For example, if you type “FirstN,” IntelliSense would list the control name FirstNameTextBox (if that control is on the form). When you open a parameter list for a function call, IntelliSense also lists the parameter names and their descriptions so it’s easier to see what values you must pass to the function.

Call stack The call stack window shows the sequence of function calls that lead to the current point of execution.

(14)
(15)

Introduction

What’s a program?

What is a program? In a practical sense, a Windows OS program is an executable file that you can run by double-clicking its icon. For example, the version of Microsoft Word is a program. You call that an executable program, or executable for short. The names of executable program files generally end with the extension .exe. Word, for example, is Winword.exe.

But a program is something else, as well. An executable program consists of one or more source files. A C# source file, for instance, is a text file that contains a sequence of C# commands, which fit together according to the laws of C# grammar. This file is known as a source file.

What’s C#?

(16)

Introduction

C# is

Flexible: C# programs can execute on the current machine, or they can be transmitted over the Web and executed on some distant computer.

Powerful: C# has essentially the same command set as C++ but with the rough edges filed smooth.

Easier to use: C# error-proofs the commands responsible for most C++ errors, so you spend far less time chasing down those errors.

Visually oriented: The .NET code library that C# uses for many of its capabilities provides the help needed to readily create complicated display frames with drop-down lists, tabbed windows, grouped buttons, scroll bars, and background images, to name just a few.

Internet-friendly: C# plays a pivotal role in the .NET Framework, Microsoft’s current approach to programming for Windows, the Internet, and beyond. .NET is pronounced dot net.

Secure: Any language intended for use on the Internet must include serious security to protect against malevolent hackers.

Finally, C# is an integral part of .NET.

The C# programming language was designed for developing programs for Microsoft’s .NET

(17)

.NET Solution

What’s .NET?

.NET began several years ago as Microsoft’s strategy to open up the Web to mere mortals like you and me. Today, it’s bigger than that, encompassing everything Microsoft does. In particular, it’s the new way to program for Windows. It also gives a C-based language, C#, the simple, visual tools that made Visual Basic so popular.

Goals for the Next-Generation Platform Services

(18)

.NET Solution

The .NET Framework is an integral Windows component that supports building and running the next generation of applications and XML Web services.

The .NET Framework is designed to fulfill the following objectives:

•to provide a consistent object-oriented programming environment whether object code is stored and executed locally, executed locally but Internet-distributed, or executed remotely;

•to provide a code-execution environment that minimizes software deployment and versioning conflicts;

•to provide a code-execution environment that promotes safe execution of code, including code created by an unknown or semi-trusted third party;

•to provide a code-execution environment that eliminates the performance problems of scripted or interpreted environments;

•to make the developer experience consistent across widely varying types of applications, such as Windows-based applications and Web-based applications;

(19)

.NET Features

Some of its features include the following:

Multiple platforms: The system runs on a broad range of computers, from servers and desktop machines to PDAs and cell phones.

Industry standards: The system uses industry-standard communication protocols, such as XML, HTTP, SOAP, JSON, and WSDL.

(20)

Components of the .NET Framework

The .NET Framework consists of three components.

The execution environment is called the Common Language Runtime (CLR). The CLR manages program execution at run time, including the following:

Memory management and garbage collection;

Code safety verification;

Code execution, thread management, and exception handling.

(21)

Components of the .NET Framework

The programming tools include everything you need for coding and debugging, including the following:

The Visual Studio integrated development environment (IDE);

.NET-compliant compilers (e.g., C#, Visual Basic .NET, F#, IronRuby, and managed C++);

Debuggers;

Web development server-side technologies, such as ASP.NET and WCF.

The Base Class Library (BCL) is a large class library used by the .NET Framework and available for you to use in your programs as well.

!

(22)

Common Language Runtime

Manages memory, thread execution, code execution, code safety verification, compilation, and other system services.

(23)

Common Language Runtime

The core component of the .NET Framework is the CLR, which sits on top of the operating system and manages program execution. The CLR also provides the following services:

Automatic garbage collection;

Security and authentication;

(24)

Role of the Base Class Libraries

NET platform provides a base

class library that is available to

(25)

Role of the Base Class Libraries

The .NET Framework supplies an extensive base class library, called, not surprisingly, the

Base Class Library (BCL). (It’s also sometimes called the Framework Class Library [FCL]). You can use this extensive set of available code when writing your own programs. Some of the categories are the following:

General base classes: Classes that provide you with an extremely powerful set of tools for a wide range of programming tasks, such as file manipulation, string manipulation, security, and encryption;

Collection classes: Classes that implement lists, dictionaries, hash tables, and bit arrays;

Threading and synchronization classes: Classes for building multithreaded programs;

(26)

.NET Assemblies

When a *.dll or an *.exe has been created using a .NET-aware compiler, the resulting module is bundled into an assembly.

Regardless of which .NET language you choose to program with, understand that despite the fact that .NET binaries take the same file extension as COM servers and unmanaged Win32

binaries (*.dll or *.exe), they have absolutely no internal similarities.

NET binaries do not contain platform-specific instructions, but rather platform-agnostic

(27)

Compiling to the Common Intermediate Language

The compiler for a .NET language takes a source code file and produces an output file called an assembly. Figure illustrates the process.

An assembly is either an executable or a DLL.

The code in an assembly isn’t native machine code but an intermediate language called the Common Intermediate Language (CIL).

An assembly, among other things, contains the following items: − The program’s CIL;

(28)

Overview of Compilation and Execution

(29)
(30)

Simple program (C# and Visual Basic .NET)

using System;

namespace CalculatorExample {

class Program // app's entry point.

{

static void Main() {

Calc c = new Calc(); int ans = c.Add(10, 84);

Console.WriteLine("10 + 84 is {0}.", ans); Console.ReadLine();

} }

class Calc // The C# calculator.

{

public int Add(int x, int y) { return x + y; }

} }

.method public hidebysig instance int32 Add(int32 x, int32 y) cil managed {

// Code size 9 (0x9) .maxstack 2

.locals init (int32 V_0) IL_0000: nop

IL_0001: ldarg.1 IL_0002: ldarg.2 IL_0003: add IL_0004: stloc.0 IL_0005: br.s IL_0007 IL_0007: ldloc.0 IL_0008: ret

} // end of method Calc::Add

Imports System

Namespace CalculatorExample Module Program

Sub Main()

Dim c As New Calc

Dim ans As Integer = c.Add(10, 84)

Console.WriteLine("10 + 84 is {0}.", ans) Console.ReadLine()

End Sub End Module

Class Calc

Public Function Add(ByVal x As Integer,

ByVal y As Integer) As Integer Return x + y

End Function End Class End Namespace

.method public instance

int32 Add(int32 x, int32 y) cil managed {

// Code size 8 (0x8) .maxstack 2

.locals init (int32 V_0) IL_0000: ldarg.1

IL_0001: ldarg.2 IL_0002: add.ovf IL_0003: stloc.0 IL_0004: br.s IL_0006 IL_0006: ldloc.0 IL_0007: ret

(31)

The Role of .NET Type Metadata

In addition to CIL instructions, a .NET assembly contains full, complete, and accurate metadata,

which describes each and every type (class, structure, enumeration, and so forth) defined in the binary, as well as the members of each type (properties, methods, events, and so on).

CREATING OF METADATA IS COMPILER JOB !!!

Because .NET metadata is so wickedly meticulous, assemblies are completely self-describing entities.

TypeDef #2 (02000003)

--- TypDefName: CalculatorExample.Calc (02000003)

Flags : [NotPublic] [AutoLayout] [Class] [AnsiClass] [BeforeFieldInit] (00100001) Extends : 01000001 [TypeRef] System.Object Method #1 (06000003)

--- MethodName: Add (06000003)

Flags : [Public] [HideBySig] [ReuseSlot] (00000086) RVA : 0x00002090

ImplFlags : [IL] [Managed] (00000000) CallCnvntn: [DEFAULT]

hasThis

ReturnType: I4 2 Arguments Argument #1: I4 Argument #2: I4 2 Parameters

(1) ParamToken : (08000001) Name : x flags: [none] (00000000) (2) ParamToken : (08000002) Name : y flags: [none] (00000000)

class Calc // The C# calculator.

{

public int Add(int x, int y) { return x + y; }

(32)

Just-in-time compiling

The runtime is designed to enhance performance. Although the common language runtime provides many standard runtime services, managed code is never

interpreted. A feature called just-in-time (JIT) compiling

(33)

Platform independence

When Microsoft released the C# programming language and the .NET platform, they also crafted a set of formal documents that described the syntax and semantics of the C# and CIL languages, the .NET assembly format, core .NET namespaces, and the mechanics of a hypothetical .NET runtime engine (known as the Virtual Execution System, or VES).

Better yet, these documents have been submitted to (and ratified by) ECMA International as official international standards. The specifications of interest are (http://www.ecma-international.org):

• ECMA-334: The C# Language Specification

• ECMA-335: The Common Language Infrastructure (CLI)

Partitions of ECMA-335 Meaning in Life

Partition I: Architecture Describes the overall architecture of the CLI, including the rules of the

CTS and CLS, and the mechanics of the .NET runtime engine

Partition II: Metadata Describes the details of .NET metadata

Partition III: CIL Describes the syntax and semantics of CIL code

Partition IV: Libraries Gives a high-level overview of the minimal and complete class libraries

that must be supported by a .NET distribution.

Partition V: Annexes Provides a collection of “odds and ends” details such as class library

(34)

Open source .NET distributions

Partition IV (Libraries) defines a minimal set of namespaces that represent the core services expected by a CLI distribution (collections, console I/O, file I/O, threading, reflection, network

access, core security needs, XML manipulation, and so forth).

The CLI does not define namespaces that facilitate web development (ASP.NET), database access (ADO.NET), or desktop graphical user interface (GUI) application development

(Windows Forms/Windows Presentation Foundation).

Distribution Meaning in Life

http://www.mono-project.com The Mono project is an open source distribution of the CLI that targets various Linux distributions (e.g., SuSE, Fedora, and so on) as well as Win32 and Mac OS X.

http://www.dotgnu.org Portable.NET is another open source distribution of the CLI that runs

(35)

References

Related documents

This document describes how to insert a popup window of the TimeTrade appointment widget while keeping your own web page shaded in the background.. Using this popup widget

“In the plan of care for the Medicare payment episode for which this assessment will define a case-mix group, what is the indicated need for therapy visits (total of reasonable

ATLAS experiment searches for lepton flavour violation, new gauge boson allowing to unify quark and lepton fields, heavy charged and neutral leptons as well as for new phenomena

As an initial test for the efficiency of remnant surveys using this core selection criterion at Tier 1 depth and resolution, we have selected from the identified catalogue all

We were able to pick up the sample, place the sample in a payload compartment, close and secure the payload compartment, raise the rocket to 84.7 degrees, insert an igniter into

The Hillsborough County Public Schools Selection Policy directs me to convene the Educational Media Materials Committee to review the challenged material. The first meeting will

The functional classifi- cation of the most differentially expressed genes were performed according to the analysis of RMA top 100 genes in each main disease groups compared to

(The default value is the same as the Extension General Use field on the Site Details: Automatic Design Definition window at the time that the NE is created. Choices displayed will