Giter Site home page Giter Site logo

Comments (4)

founderio avatar founderio commented on May 24, 2024

There is a side effect to this though:
This would, very likely, silently compile if something is missing. And then panic at runtime.

The other approach, while being more space-consuming, will fail at compilation time, making it obvious immediately, that this will cause issues.

Especially in more complex applications, you want to get an error as soon as you can, so if you can make the compiler throw an error instead of the runtime, the error will be detected earlier.

The user of the library can safeguard this by adding in the appropriate
glib.{Minor,Major}Version checks at runtime, which will sidestep all the build
tag troubles.

While this would alleviate the issue somewhat, there is still a problem: The library user needs to keep track of every single call they use, and which minimum version that requires. Not sure about others, but I tend not to remember which specific version something was introduced in.

The "build tag trouble", while annoying (*), allows us to forcibly set a minimum required version, checked at compile time. This way we, as developers, get feedback from the compiler as soon as we messed up and used a function which is not available yet in our minimum version - regardless of which version we are developing with (which is in many cases NOT the minimum version supported by the application).

(*) => if we keep in mind that deprecated functions should not be removed from compilation in later versions, for obvious reasons. And if you silence the -Wdeprecated warnings it does get better.

from gotk4.

diamondburned avatar diamondburned commented on May 24, 2024

This would, very likely, silently compile if something is missing. And then panic at runtime.

This is intended; it allows the programmer to code in optional function calls that are only called when the program is running on a newer version. An example of this was the insert-hyphens property in Pango where certain distros were too old to have them.

Especially in more complex applications, you want to get an error as soon as you can, so if you can make the compiler throw an error instead of the runtime, the error will be detected earlier.

It has its cases. This isn't necessarily one of them.

While this would alleviate the issue somewhat, there is still a problem: The library user needs to keep track of every single call they use, and which minimum version that requires.

Yes, this is true. Most programmers won't care enough, and the program will likely crash once it hits that call. This is still a more avoidable problem than having it not build at all, though. One can open an issue to ask for the proper checks instead of telling them to give up.

The "build tag trouble", while annoying (*), allows us to forcibly set a minimum required version, checked at compile time. This way we, as developers, get feedback from the compiler as soon as we messed up and used a function which is not available yet in our minimum version - regardless of which version we are developing with (which is in many cases NOT the minimum version supported by the application).

This is really hard to do properly, both for the programmer and the code generator. The code generation details are mostly implementation-specific so I'll spare you that, but just making multiple files for some tiny one-liner function calls is already a lot of work for the programmer when a simple version check does the job.

Not to mention, package maintainers will have to update the package's build tags every time the upstream GTK package gets updated, which not only is a lot more work, but might also randomly break the package for users who don't always do a full system upgrade. With a simple runtime version check, that doesn't really happen.

from gotk4.

founderio avatar founderio commented on May 24, 2024

I understand you point of view, not having to worry about those tags is certainly a benefit.

There is one alternative solution I can think of.
The main purpose of my question is the error detection at an early point. I assume it would be possible for the generator to provide a list of symbols and when they were introduced - or a small additional tool based on the gir package could be built.
Then, using go/parser or similar, implement a CI tool to check for symbols in the source code which are below or above a certain GTK/Glib/etc release. Unless explicitly specified, this would be the version of the library currently available on the system.

This way both use cases would be possible: Easier compilation without build tags, AND early, static detection of issues with the library version.

What do you think?

from gotk4.

diamondburned avatar diamondburned commented on May 24, 2024

I think that sounds really complicated to implement. I'm not sure if I should really attempt that.

from gotk4.

Related Issues (20)

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.