Introduction
Thisresearchwassupportedbythe European Union and theState of Hungary, co-financedbythe European SocialFundintheframework of TÁMOP-4.2.4.A/ 2-11/1-2012-0001 ‘National Excellence Program’.
Nowadays, withtheincreasingsize and complexity of programs, testing and validatingthecodeafterchangingit play an expandingroleindevelopment. The cost of posteriorchanges and modificationsinthe program codedependshighlyonthestructuralcomplexity of theoriginalsourcecode.
FunctionalprogramminglanguageslikeErlang, containseveralspecial program constructsthatareunheard of intherealm of object-oriented and imperativelanguages. The specialsyntacticelementsmakefunctionallanguagesdifferent, theseattributescontribute to those being interestingorextraordinary, butalsoduetothese, some of theknowncomplexitymeasuresarenot, oronlythroughmodificationsusabletomeasurecode.
Notonlyit is importanttomeasurethecomplexity of thesourcecode, butalsowehavetouseittofind and correcttheprogram'serrors and badsmells. Thereforewehavedevelopedthe script languagebelowwhich is abletosolvetheseproblems.
Erlangis a functionalprogrammingenvironmentdesignedfor building concurrent and distributedfault-tolerantsystemswithsoftrealtimecharacteristics.
Automated program transformations
Inordertoaddresstheproblemwehavecreated an algorithmthatcanmeasurethestructuralcomplexity of Erlangprograms, and canprovideautomaticcodetransformationsbasedontheresults. Wehavealsodefined a script languagethatoffersthedescription of thetransformationstepsfortheconversion of different program designs.
Inouropinion, theanalysis of complexitymeasuresonthesyntaxtreecreatedfromthesourcecode and thegraphincludingsemanticinformationbuiltfromthis, allowsautomaticimprovement of thequality of thesourcecode.
Language of thetransformationscripts
Query → MetricQuery | OptQuery
OptQuery → OptiWhereLinit
Opti → OptimizeTransform
Transform → TransformName
|TransformNameParams
Params → (Attr, ValueList)
Were → whereCond
Cond → MetricRelCondValue
|CondLogConCond
Limit → limit Int
Inthespecification of thesyntaxTransformationdenotes a transformation (e.g. move_fun), Relstandsfor a relationorother operator (e.g. <,<=,>=,>,like), LogCondenotes a logical operator (e.g. "and", "or"), theCondValuecan be an integer or a designatedlexicalitem (forexample, using a module'snamewithlike). Int inthe limit sectioncan be substitutedby a positive integer. (The non- terminalelementsarewithcapitalinitialswhereasthekeywords of thelanguagebeginwithsmallletters.) Intheoptimizesectiontheappliedconversion’stransformationsteps and itsparameterscan be specified.
The complexconditionthatcan be definedafterthewherekeyword is theonethatinitiatesthemeasurements and controlstheexecution of transformations, namely, underwhatconditions a giventransformationstepshould be re-executed, and alsowhichnodes of thesemanticgraphthetoolcreatesfromthesourcecodeshould be transformed. Thereforethe "basiccondition" can be specified, which is a logicalexpression. It must containatleastonepartialexpression, whichincludes a measurablelevel of complexityonthemodulesorfunctionsdesignatedfortransformation, an arithmetic operator, aswellas a constantvalue.
Sampletransformation script
optimize
extract_fun
where
max_depth_of_cases 1
and
number_of_function< 10
Limit 2
Withthissample script wecanautomaticallyextracttheembeddedcaseexpressionsbasedonthecomplexitymetrics. The conditionsinthesecond part of the script controlthetransformationprocess, and thevalue of theLimit stopsthe script iftheconditons (Cond) can't.
Tooltoperformtransformationscripts
Wehavedeveloped a toolwhichhelpstofind and correctbadsmellsinthesourcecodeautomatically.
Inthenew version of thetoolwehaveimplementedthealgorithm and thetransformation script language, whichenablestowriteautomaticmetricbasedsourcecodetransformationsshownbelow:
Result of thetransformation script
Duringtheoperationthe script searchesfortheembeddedcaseexpressions and extractstheminto a newfunctionwithgeneratedname. The extraction is executedonallfunctionsineachmodulethat has an embeddednessgreaterthanone.
The measured maximum value of thecyclomaticnumber of thefunctions prior totheconversionwas96, and afterrestructuringitbecame 73.
We definedthesyntax of thelanguagesuitablefordescribing and executingthesequence of automatedtransformationstepsbasedon software complexitymeasurements and describedtheoperatingprinciple of theanalyzing and executionconductingalgorithmthatwasconstructedforthelanguage.
Usingexampleprograms, and theirexecutionresultswedemon-stratedtheoperability of automaticcodequalityimprovement. Besidethesyntax and thedescriptions of usecasesweshowedwhatresultscan be achievedbyusing a simple script made up of only a couple of lines.
Insummary, theanalyzing and theoptimizingalgorithmbasedoncomplexitymeasurements, whichcan be usedtoautomaticallyorsemi-automaticallyimprovethesourcecode of software writteninErlanglanguageaswellaspreviouslypublishedprogramsthatareawaitingconversion, operatedproperlyduringthetrans-formation of large-scale software. Duringthetransformationthemeaning of thesourcecodedidnotchange, and the program workedasexpectedfollowingthere-translation.
Inthefollowingbyusingtheresultspresented here wewouldliketo test theparser and thetransformationallanguageconstructedforit, onworkingclient- server based software and programsfromtheindustrialenvironment, foranalyzing and alsoimprovingthequality of thesourcecode.