Code-quality rules an AI breaks: the wrong forms
The complete source of forAI_quality_wrong.ek9, which fails to compile exactly as captioned. Shown on forAI.html.
Fails with E11068: string concatenation with 3+ parts - use string interpolation instead; E11062: call has 4+ positional arguments - use named arguments for clarity; E11064: literal in comparison/range - give it a meaningful name; E11032: variable name shadows operator keyword - use a more specific name; E11051: pure method/function returns a value but result is discarded - a pure call with no side effects achieves nothing; E11050: operator returns a value but result is discarded - assign to variable or use in expression
#!ek9 defines module bad.site.forAI.quality defines function createConnection() -> host as String port as Integer dbName as String ssl as Boolean <- connected as Boolean: host? and port? and dbName? and ssl? lockAccount() Stdout().println("Account locked") findAll() as pure -> pattern as RegEx text as String <- found as List of String: text.split(pattern) checkIfEmpty() as pure -> container as List of String <- isEmpty as Boolean: container.empty() calculateTotal() as pure -> items as List of Float <- total as Float: 0.0 cat items > total welcome() -> name as String city as String <- greeting as String? message <- "Hello " + name + ", welcome to " + city greeting: message connect() <- connected as Boolean? connection <- createConnection("localhost", 5432, "mydb", true) connected: connection guardLogin() -> attempts as Integer if attempts > 3 lockAccount() search() -> pattern as RegEx text as String container as List of String <- summary as String? matches <- findAll(pattern, text) empty <- checkIfEmpty(container) summary: `${matches} ${empty}` addTax() -> items as List of Float price as Float tax as Float calculateTotal(items) price.+(tax)
Download forAI_quality_wrong.ek9 - it fails to compile on purpose, with the error its @Error line states.