Review this class. Are the names meaningful and consistent?
← Getting Started · Ref: Q1026
The naming is mostly good but has two issues:
1. 'proc' is too abbreviated — rename to 'processOrder' or 'fulfil'. Method names should describe the action clearly.
2. 'x' for the discount amount is meaningless — rename to 'discountAmount' or 'savings'. Local variables should describe what the value represents.
The rest is fine:
- 'Order' is a clear class name
- 'totalPrice' and 'customerName' are descriptive fields
- 'applyDiscount' clearly states the action
- 'discountRate' describes the parameter's role
Good naming makes code self-documenting. A reader should understand the purpose of each variable without reading the implementation.
Example
defines module qa.gettingstarted.reviewernaming defines class Order totalPrice as Float? customerName as String? default private Order() Order() -> name as String price as Float this.customerName: name this.totalPrice: price applyDiscount() -> discountRate as Float <- discountAmount as Float: Float() if discountRate? discountAmount: totalPrice * discountRate override operator ? as pure <- rtn as Boolean: customerName? and totalPrice? operator $ as pure <- rtn as String: `Order for ${customerName}` defines program NamingReviewDemo() stdout <- Stdout() order <- Order("Alice", 100.0) saving <- order.applyDiscount(0.15) stdout.println(`${order} saving: ${saving}`)
Common mistakes
E11031 — The name 'val' is one of the banned non-descriptive variable names, so 'val <- ...' triggers E11031 — use a descriptive name like saving. See ek9 -h E11031 for details.
Incorrect:
val <- order.applyDiscount(0.15) stdout.println(`${order} saving: ${val}`)
Correct:
saving <- order.applyDiscount(0.15) stdout.println(`${order} saving: ${saving}`)
Other ways to ask this
- Is the naming in this code good enough?
- Check if my variable and method names are clear
- Review my naming choices in this EK9 class
Coming from another language?
EK9 naming follows the same clean-code principles as any language. Use descriptive names that state purpose.
Keywords: review, quality, readable, clean, naming