basic course for junior web developer

Post on 12-Jul-2015

1.282 Views

Category:

Technology

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Basic courseBasic course

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

OutlineOutline

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

Web modelWeb model

Server

Client

Protocols

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, …

Write good codeWrite good code

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

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)

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.

Good code - common theoryGood code - common theory

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

Good piece of codeGood piece of code

Variable spanVariable span Time spanTime span

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);

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

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)

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

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

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.

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);}

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.

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.

Thanks for listeningThanks for listening

top related