if you want to have fun try to identify the number of times certain parts are duplicated inside the same method.
Stef mostRecent: projName onServer: aServerDirectory "Find the exact fileName of the most recent version of project with the stem name of projName. Names are of the form 'projName|mm.pr' where mm is a mime-encoded integer version number. File names may or may not be HTTP escaped, %20 on the server." | stem list max goodName triple num stem1 stem2 rawList nothingFound unEscName | self flag: #bob. "do we want to handle unversioned projects as well?" nothingFound := { nil. -1 }. aServerDirectory ifNil: [ ^ nothingFound ]. "23 sept 2000 - some old projects have periods in name so be more careful" unEscName := projName unescapePercents. triple := Project parseProjectFileName: unEscName. stem := triple first. rawList := aServerDirectory fileNames. rawList isString ifTrue: [ self inform: 'server is unavailable'. ^ nothingFound ]. list := rawList collect: [ :nnn | nnn unescapePercents ]. max := -1. goodName := nil. list withIndexDo: [ :aName :ind | (aName beginsWith: stem) ifTrue: [ num := (Project parseProjectFileName: aName) second. num > max ifTrue: [ max := num. goodName := rawList at: ind ] ] ]. max = -1 ifFalse: [ ^ Array with: goodName with: max ]. "try with underbar for spaces on server" (stem includes: $ ) ifTrue: [ stem1 := stem copyReplaceAll: ' ' with: '_'. list withIndexDo: [ :aName :ind | (aName beginsWith: stem1) ifTrue: [ num := (Project parseProjectFileName: aName) second. num > max ifTrue: [ max := num. goodName := rawList at: ind ] ] ] ]. max = -1 ifFalse: [ ^ Array with: goodName with: max ]. "try without the marker | " stem1 := stem allButLast , '.pr'. stem2 := stem1 copyReplaceAll: ' ' with: '_'. "and with spaces replaced" list withIndexDo: [ :aName :ind | (aName beginsWith: stem1) | (aName beginsWith: stem2) ifTrue: [ (triple := aName findTokens: '.') size >= 2 ifTrue: [ max := 0. goodName := rawList at: ind ] ] ]. "no other versions" max = -1 ifFalse: [ ^ Array with: goodName with: max ]. ^ nothingFound "no matches" _______________________________________________ Pharo-project mailing list [hidden email] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project |
((Project class parseTreeFor: #mostRecent:onServer:) allChildren
reject: [ :each | each isVariable ]) asBag sortedCounts first: 20 5x RBLiteralValueNode(-1) 3x RBMessageNode(Array with: goodName with: max) 3x RBMessageNode(max = -1) 3x RBAssignmentNode(goodName := rawList at: ind) 3x RBSequenceNode(^ Array with: goodName with: max) 3x RBReturnNode(^ nothingFound) 3x RBMessageNode(max = -1 ifFalse: [ ^ Array with: goodName with: max ]) 3x RBBlockNode([ ^ Array with: goodName with: max ]) 3x RBMessageNode(rawList at: ind) 3x RBReturnNode(^ Array with: goodName with: max) 2x RBBlockNode([ num := (Project parseProjectFileName: aName) second. num > max ifTrue: [ max := num. goodName := rawList at: ind ] ]) 2x RBMessageNode((Project parseProjectFileName: aName) second) 2x RBAssignmentNode(num := (Project parseProjectFileName: aName) second) 2x RBAssignmentNode(max := num) 2x RBBlockNode([ max := num. goodName := rawList at: ind ]) 2x RBMessageNode((Project parseProjectFileName: aName)) 2x RBSequenceNode(max := num. goodName := rawList at: ind) 2x RBMessageNode(num > max ifTrue: [ max := num. goodName := rawList at: ind ]) 2x RBMessageNode(num > max) 2x RBLiteralValueNode(' ') ... 2009/11/10 Stéphane Ducasse <[hidden email]>: > if you want to have fun try to identify the number of times certain parts are duplicated inside the same method. > > Stef > > mostRecent: projName onServer: aServerDirectory > "Find the exact fileName of the most recent version of project with the stem name of projName. Names are of the form 'projName|mm.pr' where mm is a mime-encoded integer version number. > File names may or may not be HTTP escaped, %20 on the server." > | stem list max goodName triple num stem1 stem2 rawList nothingFound unEscName | > self flag: #bob. "do we want to handle unversioned projects as well?" > nothingFound := { nil. -1 }. > aServerDirectory ifNil: [ ^ nothingFound ]. > "23 sept 2000 - some old projects have periods in name so be more careful" > unEscName := projName unescapePercents. > triple := Project parseProjectFileName: unEscName. > stem := triple first. > rawList := aServerDirectory fileNames. > rawList isString ifTrue: > [ self inform: 'server is unavailable'. > ^ nothingFound ]. > list := rawList collect: [ :nnn | nnn unescapePercents ]. > max := -1. > goodName := nil. > list withIndexDo: > [ :aName :ind | > (aName beginsWith: stem) ifTrue: > [ num := (Project parseProjectFileName: aName) second. > num > max ifTrue: > [ max := num. > goodName := rawList at: ind ] ] ]. > max = -1 ifFalse: > [ ^ Array > with: goodName > with: max ]. > > "try with underbar for spaces on server" > (stem includes: $ ) ifTrue: > [ stem1 := stem > copyReplaceAll: ' ' > with: '_'. > list withIndexDo: > [ :aName :ind | > (aName beginsWith: stem1) ifTrue: > [ num := (Project parseProjectFileName: aName) second. > num > max ifTrue: > [ max := num. > goodName := rawList at: ind ] ] ] ]. > max = -1 ifFalse: > [ ^ Array > with: goodName > with: max ]. > > "try without the marker | " > stem1 := stem allButLast , '.pr'. > stem2 := stem1 > copyReplaceAll: ' ' > with: '_'. "and with spaces replaced" > list withIndexDo: > [ :aName :ind | > (aName beginsWith: stem1) | (aName beginsWith: stem2) ifTrue: > [ (triple := aName findTokens: '.') size >= 2 ifTrue: > [ max := 0. > goodName := rawList at: ind ] ] ]. "no other versions" > max = -1 ifFalse: > [ ^ Array > with: goodName > with: max ]. > ^ nothingFound "no matches" > _______________________________________________ > Pharo-project mailing list > [hidden email] > http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project > -- Lukas Renggli http://www.lukas-renggli.ch _______________________________________________ Pharo-project mailing list [hidden email] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project |
It is a pearl!
may be a joke for geek but I love it. STef > ((Project class parseTreeFor: #mostRecent:onServer:) allChildren > reject: [ :each | each isVariable ]) > asBag sortedCounts > first: 20 > > 5x RBLiteralValueNode(-1) > 3x RBMessageNode(Array with: goodName > with: max) > 3x RBMessageNode(max = -1) > 3x RBAssignmentNode(goodName := rawList at: ind) > 3x RBSequenceNode(^ Array with: goodName > with: max) > 3x RBReturnNode(^ nothingFound) > 3x RBMessageNode(max = -1 ifFalse: > [ ^ Array with: goodName > with: max ]) > 3x RBBlockNode([ ^ Array with: goodName > with: max ]) > 3x RBMessageNode(rawList at: ind) > 3x RBReturnNode(^ Array with: goodName > with: max) > 2x RBBlockNode([ num := (Project parseProjectFileName: aName) second. > num > max ifTrue: > [ max := num. > goodName := rawList at: ind ] ]) > 2x RBMessageNode((Project parseProjectFileName: aName) second) > 2x RBAssignmentNode(num := (Project parseProjectFileName: aName) second) > 2x RBAssignmentNode(max := num) > 2x RBBlockNode([ max := num. > goodName := rawList at: ind ]) > 2x RBMessageNode((Project parseProjectFileName: aName)) > 2x RBSequenceNode(max := num. > goodName := rawList at: ind) > 2x RBMessageNode(num > max ifTrue: > [ max := num. > goodName := rawList at: ind ]) > 2x RBMessageNode(num > max) > 2x RBLiteralValueNode(' ') > ... > > > 2009/11/10 Stéphane Ducasse <[hidden email]>: >> if you want to have fun try to identify the number of times certain parts are duplicated inside the same method. >> >> Stef >> >> mostRecent: projName onServer: aServerDirectory >> "Find the exact fileName of the most recent version of project with the stem name of projName. Names are of the form 'projName|mm.pr' where mm is a mime-encoded integer version number. >> File names may or may not be HTTP escaped, %20 on the server." >> | stem list max goodName triple num stem1 stem2 rawList nothingFound unEscName | >> self flag: #bob. "do we want to handle unversioned projects as well?" >> nothingFound := { nil. -1 }. >> aServerDirectory ifNil: [ ^ nothingFound ]. >> "23 sept 2000 - some old projects have periods in name so be more careful" >> unEscName := projName unescapePercents. >> triple := Project parseProjectFileName: unEscName. >> stem := triple first. >> rawList := aServerDirectory fileNames. >> rawList isString ifTrue: >> [ self inform: 'server is unavailable'. >> ^ nothingFound ]. >> list := rawList collect: [ :nnn | nnn unescapePercents ]. >> max := -1. >> goodName := nil. >> list withIndexDo: >> [ :aName :ind | >> (aName beginsWith: stem) ifTrue: >> [ num := (Project parseProjectFileName: aName) second. >> num > max ifTrue: >> [ max := num. >> goodName := rawList at: ind ] ] ]. >> max = -1 ifFalse: >> [ ^ Array >> with: goodName >> with: max ]. >> >> "try with underbar for spaces on server" >> (stem includes: $ ) ifTrue: >> [ stem1 := stem >> copyReplaceAll: ' ' >> with: '_'. >> list withIndexDo: >> [ :aName :ind | >> (aName beginsWith: stem1) ifTrue: >> [ num := (Project parseProjectFileName: aName) second. >> num > max ifTrue: >> [ max := num. >> goodName := rawList at: ind ] ] ] ]. >> max = -1 ifFalse: >> [ ^ Array >> with: goodName >> with: max ]. >> >> "try without the marker | " >> stem1 := stem allButLast , '.pr'. >> stem2 := stem1 >> copyReplaceAll: ' ' >> with: '_'. "and with spaces replaced" >> list withIndexDo: >> [ :aName :ind | >> (aName beginsWith: stem1) | (aName beginsWith: stem2) ifTrue: >> [ (triple := aName findTokens: '.') size >= 2 ifTrue: >> [ max := 0. >> goodName := rawList at: ind ] ] ]. "no other versions" >> max = -1 ifFalse: >> [ ^ Array >> with: goodName >> with: max ]. >> ^ nothingFound "no matches" >> _______________________________________________ >> Pharo-project mailing list >> [hidden email] >> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project >> > > > > -- > Lukas Renggli > http://www.lukas-renggli.ch > > _______________________________________________ > Pharo-project mailing list > [hidden email] > http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project _______________________________________________ Pharo-project mailing list [hidden email] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project |
Tee hee, cool beans guys :)
Niko On Tue, Nov 10, 2009 at 6:32 PM, Stéphane Ducasse <[hidden email]> wrote: > It is a pearl! > may be a joke for geek but I love it. > > STef >> ((Project class parseTreeFor: #mostRecent:onServer:) allChildren >> reject: [ :each | each isVariable ]) >> asBag sortedCounts >> first: 20 >> >> 5x RBLiteralValueNode(-1) >> 3x RBMessageNode(Array with: goodName >> with: max) >> 3x RBMessageNode(max = -1) >> 3x RBAssignmentNode(goodName := rawList at: ind) >> 3x RBSequenceNode(^ Array with: goodName >> with: max) >> 3x RBReturnNode(^ nothingFound) >> 3x RBMessageNode(max = -1 ifFalse: >> [ ^ Array with: goodName >> with: max ]) >> 3x RBBlockNode([ ^ Array with: goodName >> with: max ]) >> 3x RBMessageNode(rawList at: ind) >> 3x RBReturnNode(^ Array with: goodName >> with: max) >> 2x RBBlockNode([ num := (Project parseProjectFileName: aName) second. >> num > max ifTrue: >> [ max := num. >> goodName := rawList at: ind ] ]) >> 2x RBMessageNode((Project parseProjectFileName: aName) second) >> 2x RBAssignmentNode(num := (Project parseProjectFileName: aName) second) >> 2x RBAssignmentNode(max := num) >> 2x RBBlockNode([ max := num. >> goodName := rawList at: ind ]) >> 2x RBMessageNode((Project parseProjectFileName: aName)) >> 2x RBSequenceNode(max := num. >> goodName := rawList at: ind) >> 2x RBMessageNode(num > max ifTrue: >> [ max := num. >> goodName := rawList at: ind ]) >> 2x RBMessageNode(num > max) >> 2x RBLiteralValueNode(' ') >> ... >> >> >> 2009/11/10 Stéphane Ducasse <[hidden email]>: >>> if you want to have fun try to identify the number of times certain parts are duplicated inside the same method. >>> >>> Stef >>> >>> mostRecent: projName onServer: aServerDirectory >>> "Find the exact fileName of the most recent version of project with the stem name of projName. Names are of the form 'projName|mm.pr' where mm is a mime-encoded integer version number. >>> File names may or may not be HTTP escaped, %20 on the server." >>> | stem list max goodName triple num stem1 stem2 rawList nothingFound unEscName | >>> self flag: #bob. "do we want to handle unversioned projects as well?" >>> nothingFound := { nil. -1 }. >>> aServerDirectory ifNil: [ ^ nothingFound ]. >>> "23 sept 2000 - some old projects have periods in name so be more careful" >>> unEscName := projName unescapePercents. >>> triple := Project parseProjectFileName: unEscName. >>> stem := triple first. >>> rawList := aServerDirectory fileNames. >>> rawList isString ifTrue: >>> [ self inform: 'server is unavailable'. >>> ^ nothingFound ]. >>> list := rawList collect: [ :nnn | nnn unescapePercents ]. >>> max := -1. >>> goodName := nil. >>> list withIndexDo: >>> [ :aName :ind | >>> (aName beginsWith: stem) ifTrue: >>> [ num := (Project parseProjectFileName: aName) second. >>> num > max ifTrue: >>> [ max := num. >>> goodName := rawList at: ind ] ] ]. >>> max = -1 ifFalse: >>> [ ^ Array >>> with: goodName >>> with: max ]. >>> >>> "try with underbar for spaces on server" >>> (stem includes: $ ) ifTrue: >>> [ stem1 := stem >>> copyReplaceAll: ' ' >>> with: '_'. >>> list withIndexDo: >>> [ :aName :ind | >>> (aName beginsWith: stem1) ifTrue: >>> [ num := (Project parseProjectFileName: aName) second. >>> num > max ifTrue: >>> [ max := num. >>> goodName := rawList at: ind ] ] ] ]. >>> max = -1 ifFalse: >>> [ ^ Array >>> with: goodName >>> with: max ]. >>> >>> "try without the marker | " >>> stem1 := stem allButLast , '.pr'. >>> stem2 := stem1 >>> copyReplaceAll: ' ' >>> with: '_'. "and with spaces replaced" >>> list withIndexDo: >>> [ :aName :ind | >>> (aName beginsWith: stem1) | (aName beginsWith: stem2) ifTrue: >>> [ (triple := aName findTokens: '.') size >= 2 ifTrue: >>> [ max := 0. >>> goodName := rawList at: ind ] ] ]. "no other versions" >>> max = -1 ifFalse: >>> [ ^ Array >>> with: goodName >>> with: max ]. >>> ^ nothingFound "no matches" >>> _______________________________________________ >>> Pharo-project mailing list >>> [hidden email] >>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project >>> >> >> >> >> -- >> Lukas Renggli >> http://www.lukas-renggli.ch >> >> _______________________________________________ >> Pharo-project mailing list >> [hidden email] >> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project > > > _______________________________________________ > Pharo-project mailing list > [hidden email] > http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project > _______________________________________________ Pharo-project mailing list [hidden email] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project |
In reply to this post by Stéphane Ducasse
On 2009-11-10, at 7:40 AM, Stéphane Ducasse wrote: > if you want to have fun try to identify the number of times certain > parts are duplicated inside the same method. > > Stef Actually an interesting exercise here would be to determine who originally wrote the method, then decide is it a result of the author's original coding, or the result of 10 people hacking it. If it's mostly the result of a single author, then I'm sure some nifty tool (someone could write) could determine which other methods the person authored then kick out the more complex ones and decide if the same coding practises are followed, er then mark them as candidates for simplification? I mention this because it reminded me of a project I was on years ago where after a consultant had left we determined his code was problematic based on bug reports statistics and at 2:00 am one morning I and the senior project leader pressed *delete* on all that code base since we had decided it was cheaper to rewrite it all from scratch versus fixing it. -- = = = ======================================================================== John M. McIntosh <[hidden email]> Twitter: squeaker68882 Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com = = = ======================================================================== _______________________________________________ Pharo-project mailing list [hidden email] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project |
On Nov 10, 2009, at 8:44 PM, John M McIntosh wrote: > > On 2009-11-10, at 7:40 AM, Stéphane Ducasse wrote: > >> if you want to have fun try to identify the number of times certain >> parts are duplicated inside the same method. >> >> Stef > > Actually an interesting exercise here would be to determine who > originally wrote the method, then > decide is it a result of the author's original coding, or the result > of 10 people hacking it. > > If it's mostly the result of a single author, then I'm sure some nifty > tool (someone could write) could > determine which other methods the person authored then kick out the > more complex ones and > decide if the same coding practises are followed, er then mark them as > candidates for simplification? :) you know I found a fun one self flag: #aname. "klhkjhjk" self flag: #aname. "hkjkjhkj" > I mention this because it reminded me of a project I was on years ago > where after a consultant had > left we determined his code was problematic based on bug reports > statistics and at 2:00 am one > morning I and the senior project leader pressed *delete* on all that > code base since we had > decided it was cheaper to rewrite it all from scratch versus fixing it. :) Probably we should have done it several years ago but we are making progress daily. Stef _______________________________________________ Pharo-project mailing list [hidden email] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project |
In defence to the author, i could say, that sometimes its really hard
to follow KISS principle, especially when problem domain requires many conditions to be checked and hence you inevitably need to introduce branches in code. Sometimes, when code start stinking you can look back at model and find the way to simplify it, but sometimes you simply can't do that (consider bussiness logic ) :) And of course, for a novice programmer it is crucial to have a master, who can revise his code and teach how to write a good code, point at mistakes and so on.. Even not for novice, even i prefer to have someone who could revise my code, because in this way there are less chances that you miss something or doing awfully wrong unnoticed. 2009/11/10 Stéphane Ducasse <[hidden email]>: > > On Nov 10, 2009, at 8:44 PM, John M McIntosh wrote: > >> >> On 2009-11-10, at 7:40 AM, Stéphane Ducasse wrote: >> >>> if you want to have fun try to identify the number of times certain >>> parts are duplicated inside the same method. >>> >>> Stef >> >> Actually an interesting exercise here would be to determine who >> originally wrote the method, then >> decide is it a result of the author's original coding, or the result >> of 10 people hacking it. >> >> If it's mostly the result of a single author, then I'm sure some nifty >> tool (someone could write) could >> determine which other methods the person authored then kick out the >> more complex ones and >> decide if the same coding practises are followed, er then mark them as >> candidates for simplification? > > :) > you know I found a fun one > self flag: #aname. "klhkjhjk" > self flag: #aname. "hkjkjhkj" > >> I mention this because it reminded me of a project I was on years ago >> where after a consultant had >> left we determined his code was problematic based on bug reports >> statistics and at 2:00 am one >> morning I and the senior project leader pressed *delete* on all that >> code base since we had >> decided it was cheaper to rewrite it all from scratch versus fixing it. > > :) > > Probably we should have done it several years ago but we are making progress daily. > > Stef > _______________________________________________ > Pharo-project mailing list > [hidden email] > http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project > -- Best regards, Igor Stasenko AKA sig. _______________________________________________ Pharo-project mailing list [hidden email] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project |
Free forum by Nabble | Edit this page |