4 ms·
How would you write a component based architecture like React has? New API has moved away from the classical syntax where it would ‘extend’ React component but
by antigirl 6y ago
How would you write a component based architecture like React has? New API has moved away from the classical syntax where it would ‘extend’ React component but I assumed it was still doing prototypal inheritance. Isn’t it better for memory to have some sort of inheritance?
- mantap 6y agoHonestly these things are all variations on a theme in JavaScript. The language is flexible enough that you can write code in many different ways and they all end up being equivalently powerful. In JavaScript you have precise control over inheritance, you can specify your own algorithm for how class A inherits from classes B and C. It's a totally different beast to classical inheritance in Java that has such a bad reputation because it's such a straightjacket
- gridlockd 6y agoThe problem is that people don't realize how much of an anti-feature this sort of flexibility is. > In JavaScript you have precise control over inheritance, you can specify your own algorithm for how class A inherits from classes B and C. Yeah maybe, but please don't do that.
- mantap 6y agoIf you find that shocking you would probably drop dead at seeing what Lisp programmers get up to with macros :) Language flexibility doesn't obscure the readability of code. It enhances it. In a flexible language, unclear code is always programmer error, and programmer error is fixable. In an inflexible language, a lack of clarity can sometimes be unavoidable (e.g. java programmers forced to shoehorn everything into classes)
- gridlockd 6y ago> If you find that shocking you would probably drop dead at seeing what Lisp programmers get up to with macros :) I don't find it shocking, I think it's a sign of immaturity. Been there, done that. > Language flexibility doesn't obscure the readability of code. It enhances it. Given a language without any sorts of constraints, any program can and will be written in any conceivable style. In design - not just programming language design - constraints are generally a good thing. > In a flexible language, unclear code is always programmer error, and programmer error is fixable. Virtually all errors are fixable in principle. In practice, there's a budget. Your clever and elegant but utterly idiosyncratic abstractions are costing me money in terms of getting people onboarded. > In an inflexible language, a lack of clarity can sometimes be unavoidable (e.g. java programmers forced to shoehorn everything into classes) This is not a bad trade-off at all. A flexible language invites architecture astronauts to re-invent the concept of classes or modules over and over in slightly different ways. That's Javascript until ES6 and we're still suffering from it.
- smlckz 6y ago>> In design - not just programming language design - constraints are generally a good thing. The best example of that in programming language design I have seen is the V programming language. (https://vlang.io https://vlang.io) No global variables, no null/undefined/nil/None/... V is the only language I know in which variable shadowing is an error. (Do you know any other language with this feature/constraint?) And then I remember the handling of ''var''s in js and hoisting etc. ... sigh!
- kazinator 6y ago> Do you know any other language with this feature/constraint gcc -Werror=shadow Demo: $ gcc -Werror=shadow -x c - void foo(int x) { { int x; } } [Ctrl-D][Enter] <stdin>: In function ‘foo’: <stdin>:1:25: error: declaration of ‘x’ shadows a parameter [-Werror=shadow] <stdin>:1:14: note: shadowed declaration is here cc1: some warnings being treated as errors
- smlckz 6y agoAh! Good old C. I did not dare to open the gcc man page, now I think I will look at it. For that constraint, one have to pass an option. I want to know if any language (other than V) which has this as default.