Comments (1)
Nice idea. There are a couple potential issues with the idea as suggested:
- What about fields defined after
void operator init = auto;
? Are they included or not? In Asymptote (unlike modern C++ or even Python), the compiler generally doesn't have access to anything that hasn't happened later in the file. Technically speaking this could be worked around, but someone will find it confusing either way. I can also see a version of this in which multiple "default" constructors are allowed; so, for instance,
struct Person {
string firstname;
string lastname;
void operator init=auto;
Person[] children;
void operator init=auto;
}
might have two "default" constructors, one of which takes (firstname, lastname)
while the other takes (firstname, lastname, children)
.
2. Normally, in Asymptote (unlike C++), a method is a kind of field. So which fields should be included in the following?
struct Info {
string name;
void addname(string s) { name += s; }
arrowbar3 ab;
void operator init = auto;
}
Presumably we want to set ab
but not addname
in the default constructor. But note that, by the definition of arrowbar3
, the above is equivalent to this:
struct Info {
string name;
void addname(string s) { name += s; }
bool ab(picture, path3, material, margin3, light, light);
void operator init = auto;
}
And in this iteration, it's less clear that ab
should be a constructor parameter.
One idea to solve the latter issue would be that the constructor should reference those variables that are not explicitly initialized. So for instance, in
struct Person {
string firstname;
string lastname = 'Smith';
void operator init = auto;
}
firstname
but not lastname
would be parameters of the default initializer. On the other hand, should those explicitly initialized variables be parameters that have default values? It would also add a bit of complexity to the compiler; at the moment, there's no attempt made at compile time to keep track of whether or not a variable has been initialized.
None of this is to say that the idea cannot or should not be implemented in some form, only that careful thought is required.
One final note: While suggested improvements are always appreciated, please do keep in mind that many improvements can sit around for years before anyone gets around to implementing them (if ever), even if the improvement is straightforward and everyone agrees on what it ought to be.
from asymptote.
Related Issues (20)
- asy-latex one line processing
- Linking error on macOS with clang: `Undefined symbols for architecture x86_64: "_add_history"` etc. HOT 5
- Canβt compile LSP β <boost/filesystem/directory.hpp> missing from LspCpp/src/lsp/utils.cpp HOT 1
- Algolia DocSearch integration?
- Defining struct in a loop gives confusing error message HOT 1
- Feature request: Convert tab to 4 [/8] spaces in error message reporting
- Feature request: `var oldAsin=asin;` copies the function HOT 2
- Bug: unitsize() does not work to set unitsize of other pictures HOT 2
- Documentation of cputime is in Structure section? HOT 1
- Feature suggestion: shorthand to create a picture HOT 9
- Feature suggestion: Remove `add(picture dest, picture src, pair position)` variant as it's dangerous HOT 4
- Stack traceback on error?
- Suggestion: integrate with Typst? HOT 3
- Suggestion: `envelope` type don't need `above` passed in HOT 1
- Why does the bounding box of a frame containing just a label not just the label's bounding box? HOT 1
- Suggestion: transformations for shading tools? HOT 1
- Feature suggestion: baseline specification for inclusion in LaTeX HOT 1
- Grammar railroad diagram HOT 2
- scale command breaks graph output HOT 2
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 asymptote.