Nicer syntax for constructors
NoMoreBugs
NoMoreBugs at gmail.com
Tue Nov 20 01:55:49 UTC 2018
On Monday, 19 November 2018 at 21:36:32 UTC, Erik van Velzen
wrote:
>
>
> TypeScript:
>
> class MyClass {
> constructor(
> readonly myValue: number,
> myArgument: number,
> ) {}
> }
>
> also Kotlin:
>
> class MyClass(
> val myValue: Int,
> myArgument: String
> ) {}
>
Well, I do not 'know' either of Typescript or Kotlin - so my
statement stands correct ;-)
Of course, my argument is more about consistency, and less about
how a particular language implements a constructor.
Consistency makes code easier to write, easier to understand, and
easier to maintain.
Sadly, D, like many languages, lets you do the same things in any
number of ways - which just places more burden on programmers.
Go-lang has kinda addressed this issue..
It's also about modularity/encapsulation I guess. The function
definition is really a definition of its parts, what those parts
do, and how they work together to form the desired
'functionality'.
Lets keep 'the parts' - please.
-----
return-type function-name(parameter declarations, if any)
{
declarations
statements
}
----
More information about the Digitalmars-d
mailing list