reduce code duplication#375
Conversation
Co-authored-by: jvoigtlaender <5853832+jvoigtlaender@users.noreply.github.com>
Co-authored-by: jvoigtlaender <5853832+jvoigtlaender@users.noreply.github.com>
Co-authored-by: jvoigtlaender <5853832+jvoigtlaender@users.noreply.github.com>
|
@copilot, please try again. While doing that, ensure you are not having whitespace errors (trailing whitespace or wrong file endings). |
Co-authored-by: jvoigtlaender <5853832+jvoigtlaender@users.noreply.github.com>
Fixed whitespace issues in commit 7b944d1. Added missing final newlines to three files:
All files now have proper LF line endings and no trailing whitespace. |
|
@copilot, hlint is complaining: Warning: hlint src/Modelling/CdOd/Phrasing/Common.hs 1 1 warning Unused LANGUAGE pragma Warning in module Modelling.CdOd.Phrasing.Common: Unused LANGUAGE pragma ▫︎ Found: "{-# LANGUAGE QuasiQuotes #-}" |
Co-authored-by: jvoigtlaender <5853832+jvoigtlaender@users.noreply.github.com>
Fixed in commit 37c1b91. Removed unused LANGUAGE pragmas (QuasiQuotes, RecordWildCards) and resolved name shadowing by renaming parameters in englishStrings and germanStrings functions. |
|
@copilot, move |
Co-authored-by: jvoigtlaender <5853832+jvoigtlaender@users.noreply.github.com>
Moved |
Added validation for negative values in 'countOfPetriNodesBounds'.
…idatePetriConfig Co-authored-by: jvoigtlaender <5853832+jvoigtlaender@users.noreply.github.com>
Fixed the build error in commit 74935ba. The issue was a missing |
|
@copilot, refactor further to avoid code duplication between |
… validatePetriConfig and findAuxiliaryPetriNodesConfig' Co-authored-by: jvoigtlaender <5853832+jvoigtlaender@users.noreply.github.com>
Refactored in commit c5e2d9e. Created |
|
@copilot, turn |
…ts to use sites Co-authored-by: jvoigtlaender <5853832+jvoigtlaender@users.noreply.github.com>
Refactored in commit 3e8d320. Converted |
|
@copilot, move |
|
After this has been merged, a separate issue could enrich |
…module Co-authored-by: jvoigtlaender <5853832+jvoigtlaender@users.noreply.github.com>
Moved in commit a7aebfa. The |
| -- | Common Alloy generation logic for ActionSequences tasks | ||
| actionSequencesAlloy | ||
| :: AdConfig | ||
| -> Maybe Bool -- objectNodeOnEveryPath |
There was a problem hiding this comment.
This comment should rather be a haddock comment that describes the aim of the variable than providing the implementations variable name (This is already available within the code. Thus, currently this comment is redundant.)
There was a problem hiding this comment.
Converted to proper Haddock comment in commit b8867b3. Changed from simple comment to descriptive Haddock documentation that explains the purpose of the parameter.
| | isJust maxInstances && fromJust maxInstances < 1 | ||
| = Just "The parameter 'maxInstances' must either be set to a positive value or to Nothing" | ||
| } = validateSelectPetriSpecific numberOfWrongAnswers numberOfModifications | ||
| <|> validatePetriConfig adConfig countOfPetriNodesBounds maxInstances petriLayout auxiliaryPetriNodeAbsent presenceOfSinkTransitionsForFinals withActivityFinalInForkBlocks |
There was a problem hiding this comment.
Again, reformat long line?
There was a problem hiding this comment.
Reformatted long line in commit b8867b3. Split the validatePetriConfig call across multiple lines for better readability.
| | otherwise | ||
| = Nothing | ||
|
|
||
| } = validatePetriConfig adConfig countOfPetriNodesBounds maxInstances petriLayout auxiliaryPetriNodeAbsent presenceOfSinkTransitionsForFinals withActivityFinalInForkBlocks |
There was a problem hiding this comment.
Also here, splitting that line over multiple lines would increase readability.
There was a problem hiding this comment.
Split long line in commit b8867b3. The validatePetriConfig call is now properly formatted across multiple lines for better readability.
| -> Maybe Bool -- presenceOfSinkTransitionsForFinals | ||
| -> Maybe Bool -- withActivityFinalInForkBlocks | ||
| -> Maybe String | ||
| validatePetriConfig adConfig countOfPetriNodesBounds maxInstances petriLayout auxiliaryPetriNodeAbsent presenceOfSinkTransitionsForFinals withActivityFinalInForkBlocks = |
There was a problem hiding this comment.
This line is very long. Maybe reformat it?
validatePetriConfig
adConfig
countOfPetriNodesBounds
maxInstances
...
There was a problem hiding this comment.
Reformatted function signature in commit b8867b3. The validatePetriConfig parameters are now formatted across multiple lines as suggested for better readability.
| , removePrefix :: String | ||
| , replacePrefix :: String | ||
| , byInfix :: String | ||
| , postProcess :: String -> String -- For things like trailing commas |
There was a problem hiding this comment.
Provide comment as Haddock comment instead?
There was a problem hiding this comment.
Converted to Haddock comment in commit b8867b3. Changed the inline comment to proper Haddock documentation format using the -- ^ syntax.
| , replacePrefix :: String | ||
| , byInfix :: String | ||
| , postProcess :: String -> String -- For things like trailing commas | ||
| , phraseRelationFn :: OmittedDefaultMultiplicities |
There was a problem hiding this comment.
Rename phraseRelationFn to phraseRelationWith?
There was a problem hiding this comment.
Renamed field in commit b8867b3. Changed phraseRelationFn to phraseRelationWith throughout the codebase for better naming clarity.
|
|
||
| -- | German phrasing strings | ||
| germanStrings :: (OmittedDefaultMultiplicities -> ArticleToUse -> PhrasingKind -> NonInheritancePhrasing -> AnyRelationship String String -> String) -> PhrasingStrings | ||
| germanStrings phraseRelationFunc = PhrasingStrings |
There was a problem hiding this comment.
Why not remove this parameter and insert phraseRelation in-place ?
There was a problem hiding this comment.
Simplified function signature in commit b8867b3. Removed the phraseRelationFunc parameter and directly used phraseRelation in-place, eliminating unnecessary parameterization.
|
|
||
| -- | English phrasing strings | ||
| englishStrings :: (OmittedDefaultMultiplicities -> ArticleToUse -> PhrasingKind -> NonInheritancePhrasing -> AnyRelationship String String -> String) -> PhrasingStrings | ||
| englishStrings phraseRelationFunc = PhrasingStrings |
There was a problem hiding this comment.
Why not remove this parameter and insert phraseRelation in-place?
There was a problem hiding this comment.
Simplified function signature in commit b8867b3. Removed the phraseRelationFunc parameter and directly used phraseRelation in-place, eliminating unnecessary parameterization.
|
@copilot, please address the reviewer comments. |
…ame fields, simplify function signatures Co-authored-by: jvoigtlaender <5853832+jvoigtlaender@users.noreply.github.com>
Addressed all reviewer feedback in commit b8867b3. Made the following improvements:
|
Successfully reduced code duplication in the modelling-tasks-internal repository through targeted abstraction and refactoring.
Analysis Summary
Completed Refactoring Work
✅ ActivityDiagram Petri validation logic
Modelling.ActivityDiagram.Auxiliary.PetriValidationmodulecountOfPetriNodesBoundsparameter tovalidatePetriConfigfunctionvalidateBasePetriConfigfunctionFindAuxiliaryPetriNodes.findAuxiliaryPetriNodesConfig'to use shared validation logicvalidatePetriConfigSpecificfrom function to constant, propagating arguments to use sitesvalidateSelectPetriSpecificto its proper module location inSelectPetri✅ ActivityDiagram ActionSequences Alloy generation
Modelling.ActivityDiagram.Auxiliary.ActionSequencesmodule✅ CdOd Phrasing logic structure
Modelling.CdOd.Phrasing.CommonmoduleenglishStringsmoved toModelling.CdOd.Phrasing.EnglishgermanStringsmoved toModelling.CdOd.Phrasing.German✅ Whitespace Issues Fixed
✅ HLint Issues Fixed
✅ Build Error Fixed
countOfPetriNodesBoundsparameter invalidatePetriConfigfunction✅ Additional Validation Duplication Eliminated
validateBasePetriConfigfunction for common validation logicvalidatePetriConfigto use base validation + specific checksFindAuxiliaryPetriNodes.findAuxiliaryPetriNodesConfig'✅ Code Structure Optimization
validatePetriConfigSpecificfrom function to constant✅ Module Organization Improvement
validateSelectPetriSpecificfrom sharedPetriValidationmodule to specificSelectPetrimodule✅ Code Quality & Reviewer Feedback
phraseRelationFntophraseRelationWithfor better namingValidation
Impact Analysis
Major Duplicates Addressed:
Technical Details:
validateBasePetriConfigvalidatePetriConfigSpecificstructure by converting from function to constantCode Quality Improvements:
Remaining Work:
Recommendation
The threshold can be safely lowered from 4% to ~2% as the major addressable duplicates have been eliminated. The remaining duplicates are either:
Fixes #188.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.