scalableminds / webknossos

Visualize, share and annotate your large 3D images online
https://webknossos.org
GNU Affero General Public License v3.0
128 stars 24 forks source link

Add subclass responsibility error #7603

Open frcroth opened 9 months ago

frcroth commented 9 months ago

Sometimes methods are defined in non abstract classes that should be overrridden in subclasses. This is currently done with

  protected def getShardedChunkPathAndRange(chunkIndex: Array[Int]): Fox[(VaultPath, NumericRange[Long])] = ???

or

  protected def getShardedChunkPathAndRange(chunkIndex: Array[Int]): Fox[(VaultPath, NumericRange[Long])] = ??? // Defined in subclass

I would like something more expressive, such as

  protected def getShardedChunkPathAndRange(chunkIndex: Array[Int]): Fox[(VaultPath, NumericRange[Long])] = SubclassResponsibility

like in Smalltalk

fm3 commented 9 months ago

Good idea! The ??? is certainly not very pretty.

What do you have in mind specifically?Should the behavior also change? Or just how this looks in code?

I’m wondering if we could solve this problem in another way entirely with a clever combination of traits? (So that the kind-of-abstract base class/trait does not have to have this ??? in the first place?)

frcroth commented 9 months ago

I was thinking replacing the ??? in code so that it is more expressive. The behavior does not have to change (an exception is thrown when called). Just seeing ??? it is not clear if that means "Case can not happen, trust me bro" or "I don't care" or this.