29
1 Professionalism in Programming Alexander Stepanov

1 Professionalism in Programming Alexander Stepanov

Embed Size (px)

Citation preview

Page 1: 1 Professionalism in Programming Alexander Stepanov

1

Professionalism in

Programming

Professionalism in

Programming

Alexander StepanovAlexander Stepanov

Page 2: 1 Professionalism in Programming Alexander Stepanov

2

AbstractAbstractAbstractAbstract

Programming is about writing code. The code could be good or bad and it is not a matter of personal taste.

Programming is a profession. It requires constant professional education and professional ethics.

It is essential that organizational structures support writing of professional code and maintaining professional workforce.

Page 3: 1 Professionalism in Programming Alexander Stepanov

3

Tracker& Tracker::GetTracker(void){            // FIX_ME: 9/2/99 - Why is this here? It should be

//explained with a            // comment, or removed.            if (!sTracker)            {                        int foo = 44;                        foo++;                        Signal_("sTracker == NULL");            }             PPValidatePointer_(sTracker);             return *sTracker;}

Page 4: 1 Professionalism in Programming Alexander Stepanov

4

bool PictureRadioButton::Track(Tracker& tracker){

bool result = false;Action theAction = tracker.GetAction();switch (theAction){

case kButtonDownAction:{

NRect localRect;NPoint point;bool needDraw = false;

GetLocalRect(localRect);tracker.GetPoint(point);

if (fButtonDown){

if (localRect.Contains(point)){

if ((GetItemStyle() & kRadioButtonAllowNoneSetStyle) == 0)SetBooleanValue(true);

else{

SetBooleanValue(false);fButtonDown = false;

}}

}else {

if (localRect.Contains(point)){

if ((GetItemStyle() & kRadioButtonAllowNoneSetStyle) == 0)SetBooleanValue(true);

else{

SetBooleanValue(true);fButtonDown = true;

}}

}Invalidate();Update();

result = true;break;

}

}return result;

}

Page 5: 1 Professionalism in Programming Alexander Stepanov

5

bool PictureRadioButton::Track(Tracker& tracker){

bool result = false;Action theAction = tracker.GetAction();switch (theAction){

case kButtonDownAction:{

NRect localRect;NPoint point;bool needDraw = false;

GetLocalRect(localRect);tracker.GetPoint(point);

if (fButtonDown){

if (localRect.Contains(point)){

if ((GetItemStyle() & kRadioButtonAllowNoneSetStyle) == 0)SetBooleanValue(true);

else{

SetBooleanValue(false);fButtonDown = false;

}}

}else {

if (localRect.Contains(point)){

if ((GetItemStyle() & kRadioButtonAllowNoneSetStyle) == 0)SetBooleanValue(true);

else{

SetBooleanValue(true);fButtonDown = true;

}}

}Invalidate();Update();

result = true;break;

}

}return result;

}

Page 6: 1 Professionalism in Programming Alexander Stepanov

6

bool PictureRadioButton::Track(Tracker& tracker){

bool result = false;switch (tracker.GetAction()){

case kButtonDownAction:{

NRect localRect;NPoint point;bool needDraw = false;

GetLocalRect(localRect);tracker.GetPoint(point);

if (fButtonDown){

if (localRect.Contains(point)){

if ((GetItemStyle() & kRadioButtonAllowNoneSetStyle) == 0)SetBooleanValue(true);

else{

SetBooleanValue(false);fButtonDown = false;

}}

}else {

if (localRect.Contains(point)){

if ((GetItemStyle() & kRadioButtonAllowNoneSetStyle) == 0)SetBooleanValue(true);

else{

SetBooleanValue(true);fButtonDown = true;

}}

}Invalidate();Update();

result = true;break;

}

}return result;

}

Page 7: 1 Professionalism in Programming Alexander Stepanov

7

bool PictureRadioButton::Track(Tracker& tracker){

if (tracker.GetAction() != kButtonDownAction) return false;

NRect localRect;NPoint point;bool needDraw = false;

GetLocalRect(localRect);tracker.GetPoint(point);

if (fButtonDown){

if (localRect.Contains(point)){ if ((GetItemStyle() & kRadioButtonAllowNoneSetStyle) == 0)

SetBooleanValue(true); else { SetBooleanValue(false); fButtonDown = false; }}

}else {

if (localRect.Contains(point)){ if ((GetItemStyle() & kRadioButtonAllowNoneSetStyle) == 0) SetBooleanValue(true); else { SetBooleanValue(true); fButtonDown = true; }}

}Invalidate();Update();return true;

}

Page 8: 1 Professionalism in Programming Alexander Stepanov

8

bool PictureRadioButton::Track(Tracker& tracker){

if (tracker.GetAction() != kButtonDownAction) return false;

NRect localRect;NPoint point;bool needDraw = false;

GetLocalRect(localRect);tracker.GetPoint(point);

if (fButtonDown){

if (localRect.Contains(point)){ if ((GetItemStyle() & kRadioButtonAllowNoneSetStyle) == 0)

SetBooleanValue(true); else { SetBooleanValue(false); fButtonDown = false; }}

}else {

if (localRect.Contains(point)){ if ((GetItemStyle() & kRadioButtonAllowNoneSetStyle) == 0) SetBooleanValue(true); else { SetBooleanValue(true); fButtonDown = true; }}

}Invalidate();Update();return true;

}

Page 9: 1 Professionalism in Programming Alexander Stepanov

9

bool PictureRadioButton::Track(Tracker& tracker){

if (tracker.GetAction() != kButtonDownAction) return false;

NRect localRect;NPoint point;

GetLocalRect(localRect);tracker.GetPoint(point);

if (localRect.Contains(point)) if (GetItemStyle() & kRadioButtonAllowNoneSetStyle)

SetBooleanValue(fButtonDown ^= true);else SetBooleanValue(true);

Invalidate();Update();return true;

}

Page 10: 1 Professionalism in Programming Alexander Stepanov

10

bool PictureRadioButton::Track(Tracker& tracker){

if (tracker.GetAction() != kButtonDownAction) return false;

NRect localRect;NPoint point;

GetLocalRect(localRect);tracker.GetPoint(point);

if (localRect.Contains(point)) SetBooleanValue(!(GetItemStyle() & kRadioButtonAllowNoneSetStyle) || fButtonDown ^= true);Invalidate();Update();return true;

}

Page 11: 1 Professionalism in Programming Alexander Stepanov

11

bool PictureRadioButton::Track(Tracker& tracker){

if (tracker.GetAction() != kButtonDownAction) return false;

NRect localRect;NPoint point;

GetLocalRect(localRect);tracker.GetPoint(point);

if (localRect.Contains(point)) SetBooleanValue(!(GetItemStyle() & kRadioButtonAllowNoneSetStyle) || fButtonDown ^= true); Invalidate();Update();return true;

}

Page 12: 1 Professionalism in Programming Alexander Stepanov

12

template <typename VisObj>inline bool doesLocalRectContainPoint(VisObj& vob, Tracker& tracker) {

NRect localRect;NPoint point;

vob.GetLocalRect(localRect);tracker.GetPoint(point);

return localRect.Contains(point);}

Page 13: 1 Professionalism in Programming Alexander Stepanov

13

bool PictureRadioButton::Track(Tracker& tracker){

if (tracker.GetAction() != kButtonDownAction) return false;

if (doesLocalRectContainPoint(*this, tracker)) SetBooleanValue(!(GetItemStyle() & kRadioButtonAllowNoneSetStyle) || fButtonDown ^= true);

Invalidate();Update();return true;

}

Page 14: 1 Professionalism in Programming Alexander Stepanov

14

C, C++ and STL are tools built by professional

programmers for professional programmers

Their effective use presupposes knowledge of the core areas of Computer Science

Page 15: 1 Professionalism in Programming Alexander Stepanov

15

Core of Computer ScienceCore of Computer ScienceCore of Computer ScienceCore of Computer Science

Data Structures and algorithms

Theory of computation

Programming Languages and Compilers

Operating systems

Computer architecture

Page 16: 1 Professionalism in Programming Alexander Stepanov

16

Common machine architectureCommon machine architectureCommon machine architectureCommon machine architecture

Reasons Ability to build diverse applications Ease to understand, analyze and extend Portability

Features Byte-addressable memory Pointers Stack-based function call

Page 17: 1 Professionalism in Programming Alexander Stepanov

17

C machineC machineC machineC machine

C abstracts from instructions C++ abstracts from data types STL abstracts from data structures

They share the same fundamental machine model!

In order to understand C++, in order to understand STL, one needs to understand C machine

Page 18: 1 Professionalism in Programming Alexander Stepanov

18

The way C handles pointers was a brilliant innovation; it solved a lot of problems that we had before in data structuring and made the programs look good afterwards.

Donald Knuth

Page 19: 1 Professionalism in Programming Alexander Stepanov

19

Value semanticsValue semanticsValue semanticsValue semantics

C has value semantics If you need pointer semantics – use pointers

C++ extends value semantics with copy constructors, assignment and destructors

STL extends value semantics on data structures and generalizes pointer semantics to iterators

Page 20: 1 Professionalism in Programming Alexander Stepanov

20

Regular types requirementsRegular types requirementsRegular types requirementsRegular types requirements

T a = b; assert(a == b); a = b; assert(a == b); T a = b; T c = b; mutate(a); assert(b == c);

No sharing

Page 21: 1 Professionalism in Programming Alexander Stepanov

21

Regular types advantagesRegular types advantagesRegular types advantagesRegular types advantages

Pass to functions Return from functions Create temporaries on the stack Store in data structures Understandable to the compiler

Copy propagation Common sub-expression elimination

Understandable to a human EXTENSIBILTY

Page 22: 1 Professionalism in Programming Alexander Stepanov

22

Sacred CowsSacred CowsSacred CowsSacred Cows

Top-down design

Object Orientation

Design Patterns

Template Metaprogramming

Page 23: 1 Professionalism in Programming Alexander Stepanov

23

Learning from the greatsLearning from the greatsLearning from the greatsLearning from the greats

Ken Thompson Simple, abstract

Lions' Commentary on UNIX 6th Edition Linux is the best modern imitation

Donald Knuth Methodical, meticulous

TEX + Web Bjarne Stroustrup

Persistent, evolutionary, pragmatic Design and Evolution of C++

Seymour Cray Efficient, minimal

(Blaauw and Brooks, Computer Architecture)

Page 24: 1 Professionalism in Programming Alexander Stepanov

24

Great BooksGreat BooksGreat BooksGreat Books

Knuth, The Art of Computer ProgrammingIf you think that you are a good programmer … read Art of Computer Programming…

Bill Gates Dijkstra, Discipline of Programming Abelson and Sussman, Structure and Interpretation

of Computer Programs Hennessy & Patterson, Computer Architecture

Page 25: 1 Professionalism in Programming Alexander Stepanov

25

Source code is the productSource code is the productSource code is the productSource code is the product

Much more time reading than writing

Code is the main communication channel

Code is documentation

Code is the asset

Aesthetics of code

Page 26: 1 Professionalism in Programming Alexander Stepanov

26

Software engineering Software engineering Software engineering Software engineering

Programs == Algorithms + Data Structures Good programmers

Know many Use them properly

80% - 20% rule Occasionally (very seldom) invent new ones

Professional standards Educational Quality Professional responsibility

Page 27: 1 Professionalism in Programming Alexander Stepanov

27

Group engineering Group engineering Group engineering Group engineering

Design Ownership

Clear Transferable

Reviewed Responsible

Code Ownership

Clear Transferable

Reviewed Responsible

Page 28: 1 Professionalism in Programming Alexander Stepanov

28

Software economicsSoftware economicsSoftware economicsSoftware economics

Code as liability Depreciation Maintenance

Organizational tax on code Lines Changes across releases Bugs

Benefits Reuse Investing into design Continuous improvement of code base

Page 29: 1 Professionalism in Programming Alexander Stepanov

29

We are heirs to a glorious tradition:

Let us be proud of what we are