How do I name class fields without triggering E11031?
← Variable Naming Rules and Conventions · Ref: Q925
Class fields follow the same banned name rules as all variables. Use names that describe what the field represents in the domain model.
EK9 bans exactly 12 non-descriptive names (E11031): temp, tmp, flag, flg, data, dat, object, obj, value, val, buffer, buf. These are case-insensitive. Names like status, state, config, handle, str, num, item, result, input, output, count, index, list, map, set, key, type, param, arg, var, ret, res are NOT banned.
Separately, E11032 bans operator keywords as variable names: empty, length, contains, abs, sqrt, close, matches.
INSTEAD OF BANNED FIELDS:
- 'val' -> 'orderTotal', 'measurementReading'
- 'tmp' -> 'swapHolder', 'intermediateResult'
- 'dat' -> 'sensorPayload', 'configEntry'
- 'buf' -> 'readChunk', 'outputAccumulator'
ALWAYS ALLOWED EXCEPTIONS:
- Single-character: x, y, z, i, j, k (math variables, loop counters)
- Compound words: connectionState, errorCount, dataSource
- Domain descriptive: customerName, orderTotal, retryLimit
Example
defines module qa.naming.inclasses defines class <?- Shows descriptive field naming in a class. -?> SensorDevice sensorId as String: String() currentReading as Float: Float() isCalibrated as Boolean: Boolean() SensorDevice() -> deviceId as String sensorId :=: deviceId recordMeasurement() -> measuredValue as Float currentReading := measuredValue isCalibrated := true operator $ as pure <- rtn as String: `${sensorId}: ${currentReading}` override operator ? as pure <- rtn as Boolean: isCalibrated? defines program InClassesDemo() stdout <- Stdout() // GOOD: descriptive field names inside class sensor <- SensorDevice("TH-001") sensor.recordMeasurement(22.5) stdout.println($sensor) // Compound words: ALLOWED as locals too errorCount <- 0 dataSource <- "network" stdout.println(`Errors: ${errorCount}, Source: ${dataSource}`) // Single-char math: ALLOWED x <- 1.0 y <- 2.0 stdout.println(`Position: ${x}, ${y}`)
Common mistakes
E11031 — The name 'data' is one of the 12 banned non-descriptive variable names, so declaring 'data' triggers E11031 — use a descriptive name like dataSource. See ek9 -h E11031 for details.
Incorrect:
data <- "network" stdout.println(`Errors: ${errorCount}, Source: ${data}`)
Correct:
dataSource <- "network" stdout.println(`Errors: ${errorCount}, Source: ${dataSource}`)
Other ways to ask this
- What field names are banned in EK9 classes?
- How do I fix E11031 in class properties?
- What should I name my class attributes in EK9?
Keywords: class, naming, E11031, property, banned, field