Comments (10)
@g4s8 but the order of parameters we can infer from the order of object attributes. In this example:
object alphabet as Book:
Text @isbn
Text @title
ctor()
alphabet:
"978-1-51916-691-3",
"The Alphabet"
ctor(String i, String t):
@isbn = i
@title = t
We know that @isbn
goes first and @title
goes next. What is the point of repeating this fact again in a constructor?
from eo.
@yegor256 It is okay, if the main constructor is used only for setting values to all the attributes. What happens for derived attributes or constants in the object?
Player player = Player.new("a"){
String .name
int .overallScore
new(String name) {
.name = name
.overallScore = 0
}
}
If the constructor allows has named arguments, it makes sense.
Player player = Player.new(name="a"){
String .name
int .overallScore
new(String name) {
.name = name
.overallScore = 0
}
}
from eo.
@yegor256 always will exists a primary constructor, even if you don't create one.
I mean, all constructor we create will be a second.
So I think we can forget this ticket.
from eo.
In some old programming languages, programs were made of 2 distincts parts, the declaration part with the initialization of variables and the actual code which is using them.
I wonder if this "usage" could be applied to OO....
Can we imagine an object having 2 modes, an initialization mode which would be just basic linking object attributes and setup, and a runtime mode (the actual simulation mode made of method calls between objects, the one that we're used to). 2 opaque and isolated worlds.
It's just an idea though, I'm saying this because what we do when creating objects and initialize their state require a different set of methods than when we use them..
from eo.
@aravindps in this case we just create a primary ctor, which accepts all arguments and then a secondary one, which provides defaults:
Player player = Player.new("a"){
String .name
int .overallScore
new(String name) {
new(name, 0)
}
new(String name, int score) {
.name = name
.overallScore = score
}
}
from eo.
I think that we need primary constructor declaration (without any code or attribute initialization) to specify parameters order. Without it attributes initialization may be ambiguous. E.g. object from Readme:
object alphabet as Book:
Text @isbn
Text @title
ctor()
alphabet:
"978-1-51916-691-3",
"The Alphabet"
ctor(String i, String t):
@isbn = i
@title = t
Text asText():
sprintf:
"ISBN is %s, title is '%s'",
@isbn,
@title
It's not clear (without primary constructor) where is title
and where is isbn
, because both paraeters are strings:
ctor()
alphabet:
"978-1-51916-691-3",
"The Alphabet"
So I suggest to declare primary constructor like this:
ctor(String isbn, String title)
- without body
- without colon
- parameter names are same as attribute names
@yegor256 , what do you say?
from eo.
We know that
@isbn
goes first and@title
goes next. What is the point of repeating this fact again in a constructor?
Looks logical, in this way we don't need primary constructors at all.
from eo.
@g4s8 I think it's important to update README too, after #112
from eo.
@yegor256 done!
from eo.
@g4s8 thanks a lot!
from eo.
Related Issues (20)
- don't fail on the first parsing error, but accumulate them all
- SnippetTest.java:293-296: Introduce OyFilesystem instead... HOT 2
- synthetic-attributes-with-to-java.yaml:56-62: Found more... HOT 3
- OyFilesystem.java:42-44: Add unit tests for...
- Are objects with levels redundant? HOT 5
- Sodg test error (clarification needed) HOT 4
- Daily script fails because invalid path HOT 1
- OptimizeMojoTest#optimizesIfExpired flaky test HOT 1
- redundant-levels.yaml:36-40: Remove redundant objects and...
- bytes-tests.eo:437-445: To enable next 4 as-bytes tests....
- jtcop: Fix problems with tests HOT 6
- pom.xml:280-284: Enable RuleAllTestsHaveProductionClass... HOT 1
- pom.xml:250-254: Enable RuleAllTestsHaveProductionClass...
- pom.xml:451-455: Enable RuleAllTestsHaveProductionClass...
- Daily pipeline is failed: No such file or directory
- EO Objects can have the same hash in the new version HOT 14
- ParsingTrain.java:68-72: Enable sparse-decoration.xsl... HOT 1
- Daily Build. Error: Process completed with exit code 127. HOT 2
- EOboolEOnotTest.java:43-47: Remove... HOT 1
- redundant-levels-with-siblings.yaml:34-39: Fix problem...
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 eo.