Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from abstract val to def in traits #788

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

RustedBones
Copy link
Contributor

@RustedBones RustedBones commented Jul 10, 2023

Prefer using def over abstract val in traits.
This increases implementation flexibility and avoid unnecessary serialization and memory usage (when referring to a constant for instance)

protected def isEmpty(v: T): Boolean
def write(c: RecordConsumer, v: T)(cm: CaseMapper): Unit
def newConverter: TypeConverter[T]
def newConverter(): TypeConverter[T]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function has a side effect and should hence be defined with parenthesis

@@ -133,7 +133,7 @@ object ProtobufField {
new ProtobufField[T] {
override type FromT = tc.FromT
override type ToT = tc.ToT
override val hasOptional: Boolean = tc.hasOptional
override def hasOptional: Boolean = tc.hasOptional
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In these implementation cases, isn't it preferable to define these fields as val (or maybe lazy val?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants