-
Notifications
You must be signed in to change notification settings - Fork 3
Concrete classes vs. abstract classes / trait #19
Comments
One of the intentions I had in mind (at least with Also, unless I am mistaken, you should be able to extend a concrete AST fine using implicit classes Also agree we should |
I think the best reason for the abstract class based variant would be that it would be trivial to adopt. In the first version, you would just add those classes into your hierarchy and make sure to implement the required methods. Then, you would change your library to accept the common types everywhere instead of your specialized ones. |
The biggest risk with concrete classes, honestly, is choosing the wrong data structures. It does seem that other languages do fine in this area though (in fact, data structures are the main reason we have the I mean you could do a sought of hybrid approach, where you have an Abstract AST, however it requires the users to provide types for the data structures they want to implement. Something like // Assuming we have something like
trait JValue[JNumberType,JArrayType <: Seq,JObjectType] {
// ...
}
type SafeJValue = JValue[BigNumber,Vector,Map[String,JValue[_,_,_]] // Equivalent to current safe
type FastJValue = JValue[String,Array,Array[JField[_,_,_]] // Equivalent to current fast
JValue[BigNumber,List,List[JField[_,_,_]]] // Some custom implementation
JValue[Decimal,List,List[JField[_,_,_]]] // Another custom implementation That way, if a user asks for a The abstract AST can also provide type converters for common representations (i.e. going from It also gives parser the ability to provide custom adapters for types which they don't parse into yet I would be happy for this approach, albeit its going to be less trivial than what we have now (I think we may need to use dependant types to get this right) |
It may have been discussed before (I skimmed through the gitter archive but didn't find anything) but I wonder if an abstract class / trait based approach would be feasible as well.
I've tried to come up some advantages / disadvantages (without giving them any priority or evaluation at this point):
Concrete AST
Advantages
Disadvantages
Abstract AST - Implementations provide concrete implementation
Advantages
Disadvantages
The text was updated successfully, but these errors were encountered: