programming 


with C#




GOALS


Expand the tools you have available to you

Computational Thinking  (Writing)

Understanding Code (Reading)

Capabilities and Limitations

Mapping Problems into Computational Framework


WHAT IS PROGRAMMING


Thinking like a computer scientist



Making a computer do what you want

An instinct to solve technical problems

Thinking like a computer scientist




Problem Solving

Not Memorization

Computational Mode of Thought


what is...


A computational mode of thought?


Computation?
(Mechanism vs. Thinking)


Knowledge?

wHAT IS... KNOWLEDGE



Declarative
Imperative

√x is y such that y² equals x
Guess G
if G is close to x → G
repeat with  (G + X/G)/2

computational thought!




Build a machine to do it



Fixed Program


fixed program


Atanasoff - 1941
(Linear Equations)

Turing Bombe - 1940s
(Cracking Enigma Codes)

Pocket Calculator

ASICs
(Bitcoin mining)

an improvement




Build a machine to do it ALL



Stored Program


stored program computer

memory: { Instr1, Instr2, Instr3, Instr4 }













PC

takeaway


Instructions. Recipe. Imperatives.


Composed of Simple Primitives


Just Six Primitives
-- Turing (1936)

programming languages



Turing Completeness


Super-Primitive

babylonian roots in X86

fild [eax]        ; put epsilon on stack
fild [ebx]        ; put x on top of stack
fild [ecx]        ; put guess (y_0) on top of stack
test:
fld st(0)         ; copy y_i on top of stack again, so that:
fmul              ; st(0) := y_i ^ 2
fsub st(2)        ; st(0) := y_i ^ 2 - x
fabs              ;
fcomp st(3)       ; if st(0) < epsilon
jc done           ; jump to done
improve:
fld st(0)         ; copy y_i
fdivr st(2) st(0) ; st(0) := x / y_i
fadd              ; st(0) := y_i + (x/y_i)
fld1
fld1
fadd              ; push 2 onto stack
fdivr st(1) st(0) ; st(0) := (y_i + (x/y_i))/2
jmp test
done:
fistp [eax]       ; return result
fstp st(0) 
fstp st(0)
fstp st(0)        ; cleanup

in other words...

babylonian roots in C#


float FindBabylonianSqRoot( float x, float epsilon, float initial = 0 ) {
    
    var guess = Math.Abs(initial);
    
    while( epsilon < Math.Abs(x - guess * guess) ) {
        guess = ((x / guess) + guess) / 2.0f;
    }

    return guess;
}

differences in languages

All equally capable, sort of

Wildly different paradigms
(ways of thinking)



high level   vs.   low level
general  vs.  targeted
interpreted  vs.  compiled



C#


Procedural,   Object-Oriented


high level   vs.   low level

general   vs.   targeted

interpreted   vs.   compiled


what makes up a language




Syntax


Semantics

Language ecosystem




Libraries

Tools

Resources


a look at c#



functions



actually, ... procedures!



inputs and outputs



variables



operators



flow control



standard library



demonstration





(Visual Studio 2012 Express)

First Slide

By Clayton Hughes

First Slide

  • 82