Komponentové programovanie 2
Kvalita kódu, refaktorizácia,
balíky [Link] a [Link], regulárne výrazy
Jaroslav Porubän
[Link]@[Link]
©KPI TUKE, 2017
Katedra počítačov a informatiky FEI TU Košice
Source Code Quality Matters!
Same nutrition facts
Dramatically Different Feeling!
Katedra počítačov a informatiky FEI TU Košice
Who is a Good Programmer?
Algorithms
Code
Quality Technology
Really Good Programmer
Katedra počítačov a informatiky FEI TU Košice
Code Quality
• Human readable names are very
important
– identifiers
– code conventions
• Code structuring and readability
• Applying principles, idioms, patterns
– DRY (Don't repeat yourself) principle
– Code Reuse
– Defensive programming
– Separation of concerns
Java code conventions
[Link]
Katedra počítačov a informatiky FEI TU Košice
Refactoring
Improving the Code Quality
• Process of restructuring existing code
without changing its external behavior
– improves nonfunctional attributes of the
software
• Supported by today IDE’s
– together with code generation support
• Software evolution is permanent
– code quality decreases with the time because
of changes in the software requirements,
technologies
Katedra počítačov a informatiky FEI TU Košice
Basic Classes in Java
Worth to know them
• Package [Link]
– Object
– wrapper classes: Byte, Short, Integer, ...
– String vs. StringBuilder
– System, Runtime
– Math
• Package [Link]
– Calendar, Date (see also [Link])
– Locale
– Formatter, Scanner
– Random
Numbers and strings
[Link]
Katedra počítačov a informatiky FEI TU Košice
Regular Expressions
Also worth to know them
• Package [Link]
– Pattern – compiled regular expression
– Matcher – engine for matching
• String function matches
"821224/8765"
.matches("[0-9]{6}/[0-9]{3, 4}")
"[Link]@[Link]"
.matches("\\w+[.]\\w+@tuke[.]sk")
Regular Expressions
[Link]
Katedra počítačov a informatiky FEI TU Košice
Minesweeper – Console User
Interface
Regular Expression: ([OM])([A-I])([1-9])
group 3 - column
group 2 - row
group 1 - command