Post on 17-May-2015
description
Pyramid
A talk by Alexandru Bolboaca
Developer
of
@alexbolyalex.bolboaca@mozaicworks.com
Skills
A guesstimate
80% of you are in a context where you:
1.Work on an existing codebase2.Sometimes encounter strange issues3.Have difficulties changing parts of code4.Are under pressure to add more features / fix bugs faster
A model
1. My code doesn't work
2. My code sometimes works
3. My code always works
4. My code is easy to change
5. Bad code => changeable code
Be aware that...
1.All models are wrong, some models are useful2.This model focuses on hard skills (but soft skills are very important!)
I write code but...
It doesn't work
Level 1
Aka...● Beginner● My grandmother● Anyone you know who's not a programmer
We all wrote this type of code...
Code Sampleint main(){
string teststring;
getline(cin, teststring);
cout << teststring << endl;
int b;
for (int b = teststring.length();b <= 0; b--){
cout << teststring.at(b) << endl;
}
cout << "\n" << endl;
}
Expected: “code” => “edoc”
Loop starts after the end of the stringVariable 'b' re-declared
“\n” and endl are the same thingSource: https://answers.yahoo.com/question/index?qid=20140126105146AAaZDSN
Wrong condition
Skills required for Level 1● Starting the computer● Starting a text editor● Reading● Writing on a computer● … you get the idea
I write code but...
It sometimes works
Level 2
Aka...● Jr. programmer● “It works on my computer”● “You didn't say the server is not always named
Jane!”● “It worked yesterday”● “It's 90% done”
Code SampleON_NOTIFY( wNotifyCode, idControl, memberFxn )
afx_msg void memberFxn( NMHDR * pNotifyStruct, LRESULT * result );
typedef struct tagNMHDR {
HWND hwndFrom; // handle of control sending message
UINT idFrom;// identifier of control sending message
UINT code; // notification code; see below
} NMHDR;
Careful with the types. I searched 6 months for a bug because I used INT instead of UINT
Source: http://msdn.microsoft.com/en-us/library/9c4xka2b.aspx
Skills required for Level 2● Writing code● Lots of optimism● Perseverance● Passion for programming
I write code and...
It always works
Level 3
Aka...● Sr. programmer (why not just programmer?)
Code Sample public ResultsdotNet CalculateThreadpool(ResultsdotNet total){
ManualResetEvent[] events = new ManualResetEvent[Environment.ProcessorCount];
List<ResultsdotNet> results = new List<ResultsdotNet>();
for (int i = 1; i <= Environment.ProcessorCount; i++){
ResultsdotNet batchResult = new ResultsdotNet() { Iterations = total.Iterations / Environment.ProcessorCount, ManualResetEvent = new ManualResetEvent(false) };
results.Add(batchResult);
events[i - 1] = batchResult.ManualResetEvent;
ThreadPool.QueueUserWorkItem(new WaitCallback(CalculateCallback), batchResult);
}
WaitHandle.WaitAll(events);
foreach (ResultsdotNet batchResult in results){
total.dW += batchResult.dW;
total.dX += batchResult.dX;
total.dY += batchResult.dY;
total.dZ += batchResult.dZ;
total.W += batchResult.W;
total.X += batchResult.X;
total.Y += batchResult.Y;
total.Z += batchResult.Z;
total.Iterations += batchResult.Iterations;
}
total.dW = total.dW / results.Count;
total.dX = total.dX / results.Count;
total.dY = total.dY / results.Count;
total.dZ = total.dZ / results.Count;
total.W = total.W / results.Count;
total.X = total.X / results.Count;
total.Y = total.Y / results.Count;
total.Z = total.Z / results.Count;
return total;
}
http://www.codeproject.com/Articles/767997/Parallelised-Monte-Carlo-Algorithms-sharp
Parallelised Monte Carlo Algorithm
Long method
What is parallelised?
Unclear intent
But it works!
Skills required for Level 3● Understanding requirements● Clarifying requirements● Identifying local technical risks● Testing his/her own code; writing automated tests
for own code help● Involving team mates for a code review, pair
programming
I write code and...
It's easy to change
Level 4
Aka...● Technical Lead
Code Sampledef upload() {
def problemId = params.problemId
def problem = Problem.get(problemId)
def uploadedFile = request.getFile('solution')
if (uploadedFile.empty) {
flash.message = 'Please select a file'
forward(controller: "profile", action: "index")
return
}
createSolution(problem, uploadedFile)
redirect(action: "index")
}
def createSolution(problem, uploadedFile) {
def filename = "${userService.getUser().id}/${uploadedFile.originalFilename}"
def destinationPath = new File(filename)
destinationPath.mkdirs()
uploadedFile.transferTo(destinationPath)
new Solution(user: userService.getUser(), problem: problem, pathToSolution: filename).save()
}
Source: I TAKE Unconference Contest application
Skills required for Level 4● Clean code● Changeable design principles (eg. SOLID)● Design patterns● Automated developer testing (includes unit,
integration, end to end, acceptance testing)● Identifying risks
I can turn bad code into
Changeable code
Level 5
Aka...● Code cleaner● Consultant
Skills required for Level 5● Writing tests on existing code● Refactoring● Writing own refactoring scripts
The model
1. My code doesn't work
2. My code sometimes works
3. My code always works
4. My code is easy to change
5. Bad code => changeable code
Remember
1.All models are wrong, some models are useful2.This model focuses on hard skills (but soft skills are very important!)
Your Questions?
“The important thing is not to stop questioning”
I'm guilty for this talk!
Alexandru Bolboacă
Trainer, coach, polyglot programmer with international experiencealex.bolboaca@mozaicworks.com
@alexboly
Photo Attributionhttp://i.images.cdn.fotopedia.com/flickr-3873843704-hd/Paris/Main_sights/Paris__Louvre_Pyramid.jpg
http://www.quotes.jotoexplorer.com/wp-content/uploads/2012/10/Albert%20Einstein%20Quotes%205.jpg
http://youthjoint.com/alpha/wp-content/uploads/2014/04/blackboard-with-chalk2.jpg