basic course for junior web developer

19
Basic course Basic course Author: Author: Vi, Truong Lap Vi, Truong Lap Contributor: Contributor: Khoa, Tran Dang Khoa, Tran Dang

Upload: tran-khoa

Post on 12-Jul-2015

1.285 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Basic course for junior web developer

Basic courseBasic course

Author: Author: Vi, Truong LapVi, Truong LapContributor:Contributor: Khoa, Tran DangKhoa, Tran Dang

Page 2: Basic course for junior web developer

OutlineOutline

Web modelWeb model Write good codeWrite good code Best practices in codingBest practices in coding

Page 3: Basic course for junior web developer

Web modelWeb model

Server

Client

Protocols

Page 4: Basic course for junior web developer

Web model (cont)Web model (cont)

Servers: Servers: Server languages and framework: ASP.NET, JSP, Server languages and framework: ASP.NET, JSP,

PHP, Ruby,…PHP, Ruby,… Server software: Apache, IIS, Tomcat, Resin, …Server software: Apache, IIS, Tomcat, Resin, …

Client: Client: Scripting language: JavaScript, VBScript, …Scripting language: JavaScript, VBScript, … Client technology: Ajax, Flash, Silver LightClient technology: Ajax, Flash, Silver Light

Protocols: HTTP, FTP, HTTPS, …Protocols: HTTP, FTP, HTTPS, … Common techniques: XML, …Common techniques: XML, …

Page 5: Basic course for junior web developer

Write good codeWrite good code

What is good code?What is good code? Good code - common theoryGood code - common theory

Page 6: Basic course for junior web developer

What is good code ?What is good code ?

Good code is code that you are proud to Good code is code that you are proud to release. Code that you know you have release. Code that you know you have done your best on. Code that you “know” done your best on. Code that you “know” works, and that you have given the best works, and that you have given the best design you can think of in the time design you can think of in the time available. This is not perfection, it is available. This is not perfection, it is diligence; it is professionalism. (Robert C. diligence; it is professionalism. (Robert C. Martin)Martin)

Page 7: Basic course for junior web developer

What is good code (cont)What is good code (cont)

It should be very high in business value.It should be very high in business value. Test coverage should be near 100%Test coverage should be near 100% It should be simple (KISS)It should be simple (KISS) It should have as little duplication as It should have as little duplication as

possible. (DRY)possible. (DRY) It should be expressive. It should be expressive.

Page 8: Basic course for junior web developer

Good code - common theoryGood code - common theory

Good piece of codeGood piece of code Good functionGood function Good classGood class

Page 9: Basic course for junior web developer

Good piece of codeGood piece of code

Variable spanVariable span Time spanTime span

Page 10: Basic course for junior web developer

Good piece of code (cont)Good piece of code (cont)

var world = new World();var eva = world.CreateWoman();var adam = world.CreateMan();world.CreateTheHeaven();world.CreateAnimal();…world.AddMan(adam)world.AddWoman(eva)world.CreateLove(adam, eva);

Page 11: Basic course for junior web developer

Good piece of code (cont)Good piece of code (cont)

var world = new World();world.CreateTheHeaven();world.CreateAnimal();…var adam = world.CreateMan();world.AddMan(adam)var eva = world.CreateWoman();world.AddWoman(eva)world.CreateLove(adam, eva);

Better

Page 12: Basic course for junior web developer

Good functionGood function

The name must be short but describe The name must be short but describe exactly what a function does.exactly what a function does.

Each function should < 25 lines Each function should < 25 lines Do not create side effects.Do not create side effects. Do not use many indent IF levels in the Do not use many indent IF levels in the

function. (max = 4)function. (max = 4)

Page 13: Basic course for junior web developer

Good classGood class

Good nameGood name Good designGood design

High cohesionHigh cohesion Loose couplingLoose coupling

Good for testingGood for testing Should define “extension slots” to plug Should define “extension slots” to plug

external factor for testingexternal factor for testing

Page 14: Basic course for junior web developer

Best practices in codingBest practices in coding

Do not trust anything – before testingDo not trust anything – before testing Use the strength of language to make your Use the strength of language to make your

code simplest and expressive.code simplest and expressive. Do not add redundant commentsDo not add redundant comments Arrange your idea before codingArrange your idea before coding

Page 15: Basic course for junior web developer

Do not trust – before testingDo not trust – before testing

WHAT MAY BE WRONG HERE?

public string printMoneyAmount(double number) { string readNumber = NumberUtil.readNumber(number); return readNumber.Trim() + “ $”;}NumberUtil is a class of an external library.

Page 16: Basic course for junior web developer

Make your code simplest and Make your code simplest and expressiveexpressive

bool manExist = CheckManExist(world);bool womanExist = CheckWomanExist(world);If (manExist==womanExist && manExist == true) { return CreateChildren(world);}

If (manExist && womanExist) { return CreateChildren(world);}

Page 17: Basic course for junior web developer

Do not add redundant Do not add redundant commentscomments

function CreateCardGame() { //load players join the game from database IList players = LoadJoinedPlayers(); ….

}

Comment WHY. Not HOW. Use your code to express

HOW.

Page 18: Basic course for junior web developer

Organize the idea before Organize the idea before codingcoding

If the idea is so complex => Divide it into If the idea is so complex => Divide it into small ideas/problems.small ideas/problems.

You must know what you should do You must know what you should do exactly before coding.exactly before coding.

Coding = Use the code to express your Coding = Use the code to express your idea.idea.

Page 19: Basic course for junior web developer

Thanks for listeningThanks for listening