HumanTalk - Commentaires, je t'aime un peu, beaucoup, à la folie, pas du tout

Post on 03-Aug-2015

215 views 0 download

Transcript of HumanTalk - Commentaires, je t'aime un peu, beaucoup, à la folie, pas du tout

Commentaires, je t’aime… un peu, beaucoup, à la folie, pas du tout

Pas du tout

r = n / 2;while ( abs( r - (n/r) ) > t ) {r = 0.5 * ( r + (n/r) );}System.out.println( "r = " + r );

A la folie !'*************************************************' Name: CopyString'' Purpose: This routine copies a string from the source' string (source) to the target string (target).'' Algorithm: It gets the length of "source" and then copies each' character, one at a time, into "target". It uses' the loop index as an array index into both "source"' and "target" and increments the loop/array index' after each character is copied.'' Inputs: input The string to be copied'' Outputs: output The string to receive the copy of "input"'' Interface Assumptions: None'' Modification History: None'' Author: Dwight K. Coder' Date Created: 10/1/04' Phone: (555) 222-2255' SSN: 111-22-3333' Eye Color: Green' Maiden Name: None' Blood Type: AB-' Mother's Maiden Name: None' Favorite Car: Pontiac Aztek' Personalized License Plate: "Tek-ie"'*************************************************

Ce genre de commentaires// Declare category id for productsconst int prodCategoryId = 1024;

// Create an iterator over productsvector<Product>::iterator iter = products_.begin();

// Iterate through all productsfor ( ; iter != products_.end(); ++iter ){ // Assign categody id to each product iter->AssignCategoryId( prodCategoryId );} // end for

Cela me fait penser à :// Increase i by onei++;

Le « Pourquoi », et non le « Comment »

// Assign categody id to each productconst int prodCategoryId = 1024;vector<Product>::iterator iter = products_.begin();

for ( ; iter != products_.end(); ++iter ){ iter->AssignCategoryId( prodCategoryId );}

Je nommerais correctement mes variablesJe nommerais correctement mes variablesJe nommerais correctement mes variablesJe nommerais correctement mes variablesJe nommerais correctement mes variablesJe nommerais correctement mes variablesJe nommerais correctement mes variablesJe nommerais correctement mes variablesJe nommerais correctement mes variablesJe nommerais correctement mes variablesJe nommerais correctement mes variablesJe nommerais correctement mes variablesJe nommerais correctement mes variablesJe nommerais correctement mes variablesJe nommerais correctement mes variablesJe nommerais correctement mes variablesJe nommerais correctement mes variablesJe nommerais correctement mes variablesJe nommerais correctement mes variablesJe nommerais correctement mes variablesJe nommerais correctement mes variablesJe nommerais correctement mes variablesJe nommerais correctement mes variablesJe nommerais correctement mes variablesJe nommerais correctement mes variablesJe nommerais correctement mes variablesJe nommerais correctement mes variablesJe nommerais correctement mes variablesJe nommerais correctement mes variablesJe nommerais correctement mes variablesJe nommerais correctement mes variablesJe nommerais correctement mes variablesJe nommerais correctement mes variablesJe nommerais correctement mes variables

const int bookCategoryId = 1024;

void assignCategoryToEachProducts(int categoryId, vector<Product> products){ vector<Product>::iterator productsIterator = products.begin();

for ( ; productsIterator != products.end(); ++productsIterator ){ productsIterator->AssignCategoryId( categoryId );}

}

Voyez un commentaire comme un aveu de faiblesse

Codez toujours en pensant que celui qui maintiendra votre code est un psychopathe qui connait votre adresse

Martin Golding

Imperative vs

Declarative

var numbers = [1,2,3,4,5]var doubled = []

for(var i = 0; i < numbers.length; i++) { var newNumber = numbers[i] * 2 doubled.push(newNumber)}console.log(doubled) //=> [2,4,6,8,10]

var numbers = [1,2,3,4,5] var doubled = numbers.map(function(n) { return n * 2})console.log(doubled) //=> [2,4,6,8,10]

var dogsWithOwners = []var dog, owner

for(var di=0; di < dogs.length; di++) { dog = dogs[di]

for(var oi=0; oi < owners.length; oi++) { owner = owners[oi] if (owner && dog.owner_id == owner.id) { dogsWithOwners.push({ dog: dog, owner: owner }) } }}}

SELECT * from dogsINNER JOIN ownersWHERE dogs.owner_id = owners.id

var data = [{x: 5, y: 10}, {x: 20, y: 5}]

var circles = svg.selectAll('circle') .data(data)

circles.enter().append('circle') .attr('cx', function(d) { return d.x }) .attr('cy', function(d) { return d.y }) .attr('r', 0) .transition().duration(500) .attr('r', 5)

D3.js

Merci

Source : http://latentflip.com/imperative-vs-declarative/

http://www.infoq.com/news/2010/03/To-Comment-or-Not-to-Comment

http://blog.codinghorror.com/coding-without-comments/