Comments (5)
I'm not completely opposed. It does simplify some things in many areas, and regardless of what road we undertake we should encourage having at most one init
function, be that through the linter and/or Effective Gno.
That being said, we still need to consider that:
- Restricting
init
to only being declarable once would entail a deviation from the Go spec, marking the first "true" incompatibility from the Go specification (the ones we have, like the lack of complex numbers, goroutines and channels, are all features that we'll probably consider adding in some capacity) - Restricting
init
to being declarable only once does not improve "security" when auditing a contract, but the existance of the feature to a biased Go programmer may invoke a false sense of security (due to being unaware of variable initialisation through self-executing closures).
For this reason, I think it makes more sense to have init
declarable once as a recommendation rather than a language change.
from gno.
Yep, I hear what you are saying in terms of deviating from Go spec and I like that recommendation as a good middleground without introducing further complications. It's good we've had a discussion on this to refer back to and support what is found in Effective Gno/best practices/recommendations.
from gno.
Furthering the conversation on this, since we are not using this in the same way as Go- rather we are using it as a constructor function to execute only a single time during its lifecycle (at deployment)- having multiple constructors could actually be problematic since those coming from other smart contract languages (eg, Solidity) are accustomed to only declaring a single constructor function within their application, despite having multiple files; in other words, there is no constructor "overloading" allowed.
If we choose to continue allowing constructor "overloading," at the very least we should make it apparent in the documentation that whatever data is set within these constructors may get overwritten (especially if the same variable is mentioned) which could lead to unintended consequences or, at least, create a confusing order of operations when determining which init
executes before the other if there are multiple found present in an app.
from gno.
Just a quick note: there will almost certainly always be ways to create "multiple constructor functions", even if we restrict init to being declarable only once.
The reason is that there is a ""secret"" alternative way to express the init function:
package hello
func main() {
println(x)
}
var x int
var _ = func() int {
x = 11
return 0
}()
This will output 11
-- and is intended behaviour.
Variables can be initialised to any expression without restriction per the Go spec (excluding cyclical references, whereby then initialization order could not be determined).
So, while I get your point in theory, unless we also change variable initialization radically for Gno (such as, disabling it entirely, which I don't think is a good idea) there will always be ways for people to have "hidden initialisation side-effects" in other files.
from gno.
That's true, but your example isn't a widely used concept and one that is expressed within Go standard documentation (+ Effective Go); in other words, though it works, it feels more like a hack.
What I am suggesting is taking what Go programmers ordinarily understand to be normal behavior (multiple init
scattered throughout their app for db initializations, etc.) and restricting it to a single declaration so they don't do something which could create unintended consequences because the behavior of our init
is different than that of Go's.
from gno.
Related Issues (20)
- [GnoVM]: Do not allow realms to store references to objects owned by other realms
- RFC(philosophy): Limiting depth of commands and subcommands in CLIs HOT 1
- RFC(philosophy): Merge some standalone repos into this monorepo
- [Discussion/Request] Add a way to catch emitted events in `gno test` HOT 1
- `Time.Now()` always return initial UNIX time HOT 2
- [gnokey] Make `gnokey query` more convenient HOT 3
- main README should disambiguate with gnosis project
- Oracle VRF HOT 2
- out of gas error is unclear `(VM call panic {WritePerByte})` HOT 2
- Incompatibility of `gnoland secrets init` with Read-Only mounted k8s Secrets
- [GnoVM] `TestSetRealm` not working properly in `gno test` HOT 3
- contribs/gnokeykc has only tm2 features (missing thinkgs like maketx addpkg)
- RFC(gnovm): make all gno unit tests independent (and parallel)
- Validators cannot discover P2P peers when running as `StatefulSet` in k8s HOT 4
- [gnoland] Add `namespace` RPC endpoint HOT 2
- bug(gnovm): incorrect type comparison HOT 3
- Add/append balances and txs when genesis exists HOT 3
- [docs] Update outdated images & gifs
- CI issue about contribs/ is only triggered after PR merges HOT 1
- Is it possible to have a dedicated CI error when it's just Codecov?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gno.