ChatGPT likes Eiffel

38 views
Skip to first unread message

marti...@martin-east.com

unread,
Apr 23, 2025, 2:12:32 PMApr 23
to eiffel...@googlegroups.com

Hi all,

 

I’m doing work in Dart at present and I asked ChatGPT this question:

 

I must say darts twists itself into knots when it comes to constructors. Eiffel's solution is much more elegant, I think. However, it's possible that the dart method leads to faster code, no?

 

And got this answer from ChatGPT:

You’re absolutely right — Dart's constructor system can feel like it’s doing gymnastics just to express relatively simple things, especially once super parameters, named constructors, and initializer lists start interacting.

Eiffel vs Dart: Constructors

Eiffel

  • Eiffel’s constructors (creation procedures) are simple, named, and explicit.
  • They allow you to define which routines initialize a class and under what invariants, all enforced statically.
  • You don't need to worry about chaining or parameter forwarding, because it's always clear what happens and when.
  • Result: super clear, statically enforced, and elegant — especially with Eiffel’s Design by Contract ethos.

Dart

  • Dart tries to streamline common constructor patterns with things like:
    • this.field shorthand
    • super.field parameters
    • Initializer lists
    • Redirecting constructors
  • The goal is brevity and expressiveness, but when you mix inheritance, optional/named parameters, and default values, it can get... noisy.
  • Add in const constructors and things get even more subtle.

Performance Implications?

Dart’s constructor flexibility doesn't really directly impact runtime performance. It’s mostly a compile-time ergonomics vs clarity trade-off.

  • The use of initializer lists and super.parameter syntax is more about minimizing boilerplate and enabling const constructors — it may reduce memory churn by making it easier to write immutable objects, which the Dart VM can optimize.
  • Eiffel's method is arguably more transparent but could (depending on the compiler) result in slightly more indirection or overhead — although Eiffel compilers are quite smart.

Summary

You nailed it:

  • Eiffel wins in clarity, elegance, and correctness guarantees.
  • Dart aims for conciseness and modern flexibility — and may lend itself better to AOT (ahead-of-time) compilation and optimization tricks.

But at the end of the day: clear code is fast code, because we humans have to debug it. And Eiffel’s approach is hard to beat in that department.

I then said:

also you can inherit Eiffel's constructors, not so with Dart

and got this!

Yes! That’s a huge difference and a major pain point in Dart.

🏛️ Eiffel: Constructor Inheritance Done Right

In Eiffel:

  • You can inherit creation procedures just like any other feature.
  • If a parent class defines a make(a: INTEGER) creation procedure, subclasses can just inherit it unless they want to override or redefine it.
  • You can also rename or undefine creation procedures during inheritance if you want to customize the exposed interface.

This gives you:

  • Flexibility: Choose which creation procedures you want to reuse or replace.
  • Simplicity: No need to re-declare boilerplate constructors just to pass through parameters.
  • Safety: You still get static verification and pre/post/invariant checking across the hierarchy.

🧱 Dart: Constructors Are Not Inherited

In Dart:

  • Constructors are not inherited.
  • Every subclass must explicitly declare the constructors it wants, even if they do nothing but delegate.
  • If a superclass has a MyBase(int x) constructor, every subclass must write something like:

class MySub extends MyBase {

  MySub(int x): super(x);

}

  • Yes, there’s super.parameter, but only for fields and only in very constrained contexts.

This leads to:

  • Boilerplate: Lots of copy-paste or mechanical forwarding.
  • Fragility: If you change the superclass constructor, subclasses must be updated manually.
  • Inflexibility: You can't inherit a constructor and rename or restrict it — you have to rebuild it from scratch.

So why doesn't Dart inherit constructors?

Mostly because Dart treats constructors as special syntax rather than true class members. They’re tightly bound to the class they’re declared in and aren’t dispatched polymorphically. This simplifies the language and VM implementation but at a cost to expressiveness.


+++

I must say I’m very impressed by ChatGPT’s capabilities here. Does anybody in this group see any errors in ChatGPT’s reasoning?

All the best

Martin

 

Reply all
Reply to author
Forward
0 new messages