Design Part II Getting Ready to Build!

Post on 22-Jan-2016

28 views 0 download

description

The George Washington University. Design Part II Getting Ready to Build!. Kunal Johar CSCI 4243 (Senior Design). Where are We in Design?. Specifications Document Development Idea / Problem Statement High Level Requirements Use Cases Functional / Non-Functional Requirements - PowerPoint PPT Presentation

transcript

Kunal Johar Design Part III 1

Design Part II Getting Ready to Build!

Kunal JoharCSCI 4243 (Senior Design)

The George Washington University

Kunal Johar Design Part III 2

Where are We in Design?

• Specifications Document Development– Idea / Problem Statement– High Level Requirements– Use Cases– Functional / Non-Functional Requirements– Components Needed– Workflow

Kunal Johar Design Part III 3

Where are We in Design?

• UI / Mockups

• Final Workflow

• Data Structures / Algorithms

• Third Party APIs

Kunal Johar Design Part III 4

Where Are We in Development?

• Bootcamp I Complete

• Bootcamp II in Progress

Kunal Johar Design Part III 5

What is Next?

• Design Part III– Coding Structure– Repository Setup– Test Plan– Development Task List / Estimation

• Bootcamp II

• 30% Demo!

Kunal Johar Design Part III 6

Good Code Structure

• Why Bother? What are some traits?

Kunal Johar Design Part III 7

Good Code Structure

• Remember Shop Vote?

Kunal Johar Design Part III 8

Shop Vote Code Structure

• How would you lay out your code?

Kunal Johar Design Part III 9

Which Is Better?

/Data

- Vote.java

- Images.java

/Logic

- Vote.java

- Images.java

/Configuration

- General.java

- Votes.java

/Vote

- Data.java

- Logic.java

- Configuration.java

/Images

- Data.java

- Logic.java

GeneralConfiguration.java

Kunal Johar Design Part III 10

Attributes of Good Structure

• Well defined, yet simple

• Intuitive to you and other developers

• Extensible– Supports additions without needing to create

a new “structure”

• Good News: There are techniques for this!

Kunal Johar Design Part III 11

Naming Conventions

• CONSTANTS _constants

• VariableNaming variableNaming

• Methods / Procedures()

• Classes

• Sounds a bit OO– How about C? Or LISP?

Kunal Johar Design Part III 12

Naming Conventions

• Why Have Them?– Make code readable– Common construct for developers of a

language– Fundamental to the success of an open

source project

– Makes code safer! Really.http://www.joelonsoftware.com/articles/Wrong.html

Kunal Johar Design Part III 13

Where To Start

• Find a code writing style guide– Java (http://www.oracle.com/technetwork/java/codeconv-

138413.html)

– Javascript (http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml)

– C# (http://www.akadia.com/services/naming_conventions.html)

– Haskell (http://urchin.earth.li/~ian/style/haskell.html)

– C / Systems Code (http://www.seas.gwu.edu/~gparmer/csg.pdf)

Kunal Johar Design Part III 14

Read Their Rules

• Capitalization Style– PascalCase, camelCase, UPPERCASE

• Notation– Brief: SetScrollX– Verbose: SetHorizontalScrollPosition– Hungarian: fBankBalance,

studentCurrentStudent

Kunal Johar Design Part III 15

Add Your Rules

• Special Classes

• Folder Naming Structure

• Packages / Name Spaces

• What is a Name Space?– edu.gwu.cs.BiFi

Kunal Johar Design Part III 16

Shop Vote

• C# Language

• Server Side and iPhone Application

• “Simple” application– How would you lay out the server side?– How about the client side?

Kunal Johar Design Part III 17

Shop Vote

• Even Simple Applications Need Structure

Kunal Johar Design Part III 18

Intro to Design Patterns

• Idea that code creation follows patterns depending on what code is for

• Widely accepted concepts on how to structure code

• Implemented across standard libraries for countless langages

Kunal Johar Design Part III 19

Naming Conventions on Steriods

• Creational patterns– Builders, Factories, Singleton

• Structural patterns– Wrappers, Bridges, Proxies

• Behavioral Patterns– Iterators, Observers, States

• Concurrency Patterns– Lock, Monitor, Thread, Pool

Kunal Johar Design Part III 20

Comments

• Intuitive code means fewer comments– Good naming conventions– Avoid complex code

– Loosely couple components• What does this mean?

Kunal Johar Design Part III 21

Documentation

• Comment public properties / public methods

• Use a documentation tool– http://www.stack.nl/~dimitri/doxygen/

Kunal Johar Design Part III 22

Setup a Repository

• Git, SVN, Mercurual

• Herve spoke to you about this a few weeks ago

• No excuse for not having one setup

• Decide when you will check in code– Only working code?– Only after full modules are built?– Make sure you comment your check ins

Kunal Johar Design Part III 23

In Class Exercise

• Write out the authentication class of the web service

• Then write a set of unit tests to confirm the functionality works

• Use realistic pseudocode

Kunal Johar Design Part III 24

Let’s Take a Look at ShopVote

• Model View Controller

• Makes Unit Testing a Lot Easier

• Two repositories– Server side – Client side (phone)

• [Link to code spaces]

Kunal Johar Design Part III 25

Project Management Planning

• Better idea of difficulty of your project after Bootcamp I and II

• But to get to 30% we need a Bootcamp III

• 30% - 100% can then be defined

Kunal Johar Design Part III 26

Plan a Daily Activity

• What to develop first?– The hard stuff

• What to develop last?– Get everything working– Make everything look good– Get a few things to look great

http://www.joelonsoftware.com/articles/fog0000000018.html

Kunal Johar Design Part III 27

Filling in the Empty Shell

• Build a Shell of Major Functionality

• Fill in the shell with code

• Use Unit Tests and Mock Objects to test subcomponents– These won’t catch all errors but will help

narrow them down

Kunal Johar Design Part III 28

Unit Testing

• Ensure baseline functionality works• Speeds up Debugging

• Does not require custom tools– Method stubs with expected return values

• Tools Do Help Though – JUnit / JMock– NUnit

Kunal Johar Design Part III 29

Project Management Tools

• “Task List” manager• Time Estimation

• MS Project– Large learning curve, very powerful– Useful for large projects with large teams (building an airplane)

• Assembla, Google Code, Microsoft CodePlex– Simpler task tracking “ticketing” tools– Bug Tracking / Feature Tracking– Integrate with repository

Kunal Johar Design Part III 30

Bootcamp III

• What are the remaining challenging parts of this project?

• What are the frameworks / APIs that need setup

• What do you have the least control over?

Kunal Johar Design Part III 31

ShopVote Bootcamp III

Kunal Johar Design Part III 32

30% - 100%, 110%

• Look at HW5.pdf for remaining tasks– Get the framework done

• E.g. Site map, login screens• These are easier to do now than later

– Look at your workflow steps with no dependencies

• Integrate components that depend on them• Repeat

Kunal Johar Design Part III 33

Time Estmiation

• For each task– Write a description– Write a test plan to ensure results work– Estimate Time

• Time = (Coding + Testing + Integration)*P

• P = Polish, which means 3x your expected effort

Kunal Johar Design Part III 34

Task Strategy

• For each major work flow create a single large task– Break each task into sub tasks of 4-6 hour

blocks

– Bootcamp tasks are all resolved so these remaining tasks are manageable chunks

• (Bootcamp tasks can be dozens of hours each)

Kunal Johar Design Part III 35

What can you do in 4 hours?

• Code the front end of a single UI form

• Code the backend of a single UI form

• Develop a handful of API calls

• Input a medium (15 table) database scheme and map it to code

Kunal Johar Design Part III 36

What can you do in 4 hours?

• Nothing if there are even minor distractions

• Nothing if you run into a nasty runtime error

• Nothing if you focus too hard on a minor problem (repositioning controls on a resize)

Kunal Johar Design Part III 37

Work Plan

• You know how you work besthttp://www.paulgraham.com/makersschedule.html

• I recommend– 2-4 hours of coding per day– 1 day off per week– 1 marathon coding session per week– 4 hours, 1 hours testing, 3 hours fixing,

1 hour refactoring (why?)

Kunal Johar Design Part III 38

Formulate Task List

• [Code Spaces Link]

• How long do you think each task should take us?

• Let’s talk about how long they really took us

Kunal Johar Design Part III 39

In Class Exercise

• Start work on your coding plan

• Find a naming convention

• Determine initial directory structure

• Determine Bootcamp III tasks

Kunal Johar Design Part III 40

Discipline + Good Code Structure

• Structure alone is insufficient

• We can’t forget good general coding rules

http://developerart.com/publications/4/wise-programming-techniques-for-writing-quality-code

Kunal Johar Design Part III 41

Avoid Quick Hacks

• Y = Z/N

• Transform it to

If (N == 0) {Z=0;N=1; Y= Z/N}

Kunal Johar Design Part III 42

Write Self-Explanatory Code

• SendThumbnailToAmazonS3(image);

• SendPushNotifications(contacts[], message){ foreach (contact c in contacts) SendPushNotification(message, c.DeviceID)}

Kunal Johar Design Part III 43

Avoid Showing Off

• A = A ^ BB = A ^ B

• A = A ^ B

Kunal Johar Design Part III 44

Avoid Dense Code Blocks• Acc[categoryC] += GetUniqueHours(start, end) * 24;

categoryC = NextCategory(categoryC, lookupCodes);

TotalTime += Acc[categoryC];MaxTotalTime = Acc[PrevCategory(categoryC, lookupCodes] + TotalTime;

This is the cleanest part of a 2,000 line time sheet generator that I wrote.  Updated to:

foreach (TimeSheetCategory tc in TimeSheetCategories){  decimals timeInDays = GetTimeForCategory(start, end, tc);  TotalTime += timeInDays;  TotalTimePlusOverhead += timeInDays * 2;}

Kunal Johar Design Part III 45

Avoid Duplicative Functionality

• Windows APIs– ShellExecute– ShellExecute32– ShellExecuteEx– ShellExecuteEx32– ShellExecute64

Kunal Johar Design Part III 46

Other Tips

• Avoid “magic constants”– Place all constants in a properties or config file / class

– Keep related code together

– Strive for loose coupling• What does this mean?

– Optimize last!

Kunal Johar Design Part III 47

What Are You Here For?