GithubHelp home page GithubHelp logo

Contructors and Destructors about eo HOT 22 CLOSED

objectionary avatar objectionary commented on August 16, 2024 1
Contructors and Destructors

from eo.

Comments (22)

yegor256 avatar yegor256 commented on August 16, 2024 6

@mdbs99 my initial idea was to use ctor and dtor. Let's collect some opinions and I will make changes.

from eo.

fabriciofx avatar fabriciofx commented on August 16, 2024 4

@mdbs99 I agree. constructor and destructor are better names.

from eo.

nqafield avatar nqafield commented on August 16, 2024 1

@mdbs99 Sure. And I guess it would be just as easy to find if it was always first. Just a preference I guess.

from eo.

gukoff avatar gukoff commented on August 16, 2024 1

Do we need an explicit primary constructor? It seems to be the same all the time - something which accepts all the attributes and sets them as-is.

@gukoff I don't. What I want is that compiler not check if the "primary ctor" was wrote at the end. Just that.

No, I've addressed the concept, not your particular issue :)

Speaking of languages like Java, the requirement for a primary constructor to be written at the end looks logical. It reminds me of the common rule of putting private below public. The secondary constructors must be public; otherwise, they are useless. A primary constructor is sometimes public just to be used in unit testing and serves as a basis for the secondary ones.

from eo.

mdbs99 avatar mdbs99 commented on August 16, 2024 1

...a primary constructor to be written at the end looks logical.

@gukoff I don't see any logica here sorry. Anyway...
if I can put the constructors and methods in the sequence I want, without the compiler interfering, it will just be a matter of style. That just all I need.

from eo.

krzysiekpiasecki avatar krzysiekpiasecki commented on August 16, 2024 1

Constructors must be listed after attributes. The primary constructor must be the last one. The destructor, if it is present, goes right after the primary constructor.

We're talking about inline or temporal dependencies as a bad pratice, but we should write ctors dtors attrs in a legal order.

from eo.

eugene-nikolaev avatar eugene-nikolaev commented on August 16, 2024 1

+1 for ctor/dtor

from eo.

DronMDF avatar DronMDF commented on August 16, 2024

ctor/dtor is preferred to me. Use object name as ctor/dtor is not obviously. Especially given the specialization.

Question:

object shape as Shape: ...
object rectangle extend shape:

rectangle can public shape ctor? Or base class ctor is private?

Other example:

object error as Error:
    ctor(String: what):...
object logic_error extend error:
    // Need ctor?

Hm... This extend does not make sense with some type of object. Maybe parent ctor need only for private use.

from eo.

mdbs99 avatar mdbs99 commented on August 16, 2024

@DronMDF there is no inheritance for Objects, just specialization for Types.

from eo.

DronMDF avatar DronMDF commented on August 16, 2024

Yep, sorry. extend only for types. Ok.

from eo.

nqafield avatar nqafield commented on August 16, 2024

Why the last one? The primary has to be the first, on top.

@mdbs99 Yegor wrote about this here.

from eo.

mdbs99 avatar mdbs99 commented on August 16, 2024

@pa9ey yes, I know, and agree with him — I have done this ~2 years before this article.
I guess you didn't understand me right:

Why the last one? The primary has to be the first, on top.

I meant: If the compiler will check the precedence, the primary ctor should be the first wrote in the code.

from eo.

gukoff avatar gukoff commented on August 16, 2024

Do we need an explicit primary constructor? It seems to be the same all the time - something which accepts all the attributes and sets them as-is.

from eo.

nqafield avatar nqafield commented on August 16, 2024

@mdbs99 I understood you. You were asking, Why the last one? Yegor addresses that very question in the article. I wasn't suggesting you should agree with it, nor that I do (or don't) - I was simply pointing out that he addresses your question, the one that I quoted.

from eo.

nqafield avatar nqafield commented on August 16, 2024

@gukoff Good point.

from eo.

mdbs99 avatar mdbs99 commented on August 16, 2024

@gukoff I don't. What I want is that compiler not check if the "primary ctor" was wrote at the end. Just that.

@pa9ey I'm sorry. I read the article again:
...a primary constructor, and it will always be easy to find because it stays below all secondary constructors.
Now I understood what you meant. But I disagree of Yegor in that case.

from eo.

mdbs99 avatar mdbs99 commented on August 16, 2024

So @yegor256, ctor and dtor won?

from eo.

mdbs99 avatar mdbs99 commented on August 16, 2024

@yegor256 ctor and dtor won?
Can I close this issue?

from eo.

monsieurluge avatar monsieurluge commented on August 16, 2024

+1 for constructor & destructor (readability in mind)

from eo.

gukoff avatar gukoff commented on August 16, 2024

Guys, it isn't going to be written in stone :) For the time being, both ctor and constructor are fine.

from eo.

mdbs99 avatar mdbs99 commented on August 16, 2024

@gukoff I agree with you.
So as @yegor256 didn't tell anything all these days and we've already voted, I'll finish this issue and, after, change the README if nobody does.

from eo.

yegor256 avatar yegor256 commented on August 16, 2024

@mdbs99 please submit a pull request for ctor and dtor. thanks!

from eo.

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.