GithubHelp home page GithubHelp logo

Comments (5)

Dogacel avatar Dogacel commented on June 12, 2024

I prefer the current implementation. We have a convention of adding optional to every field explicitly. But generally, It makes more sense to generate all of them nullable by default, because this convention is just a thing we made up.

Also, if field is unset in the non-null implementation, are we seeing a NullPointerException in runtime?

We use https://github.com/bufbuild/protovalidate to ensure field nullability for example. I had a long conversation in pbandk issues. Ability to generate code as nullable or not nullable based on certain options. What do you think about this?

from krotodc.

mscheong01 avatar mscheong01 commented on June 12, 2024

Also, if field is unset in the non-null implementation, are we seeing a NullPointerException in runtime?

No, these fields are set with default instances

from krotodc.

mscheong01 avatar mscheong01 commented on June 12, 2024

I also agree that having an option for both is the best way to go.

from krotodc.

Dogacel avatar Dogacel commented on June 12, 2024

Also, if field is unset in the non-null implementation, are we seeing a NullPointerException in runtime?

No, these fields are set with default instances

One reason why Proto uses unset as the default instance rather than null is recursion

message LinkedList {
  string value = 1;
  LinkedList next = 2;
}

In this case, the generated code shouldn't really work, right? I assume Kotlin code looks like this:

data class LinkedList(
  val value: String,
  val next: LinkedList,
)

Which is basically impossible to initialize. As long as code throws an appropriate error, I like it.

from krotodc.

Dogacel avatar Dogacel commented on June 12, 2024

Sorry for late response, I am reproducing the bug here: #19

Because every message is optional by default, I expect to see this behavior time to time.

from krotodc.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.