by antonvs · 6y ago · 0 comments
"Terribleness" isn't an objective property.
The comparative approach I mentioned can be used to eliminate personal feelings about such issues - not in all cases (types might be an example), but certainly in some.
Many users of Javascript, including myself, recognize that it has many weaknesses. There's even a book that acknowledges this in its title: "Javascript: The Good Parts."
Denying this seems to be denying objective reality.
You may be confusing "objective" with "universal," thinking that I'm claiming some unsituated universal truth. But that's not the case. Any statement is only ever true within some context - the language that defines it, the semantics of the statement, the premises that it assumes.
In this case, there is a shared context that crosses programming languages, that allows us in at least some cases to draw objective conclusion about programming language features. "The bad parts" implied by Crockford's title includes many such features. We can examine them and conclude that while they might have some historical rationale, that they are not good features for a programming language to have.
In many cases this conclusion is possible because there's simply no good justification - the title of this post is an example. Having all numbers be floating point has many negative consequences and no significant positive ones - the only reason for it is historical. Such features end up having consequences, such as on the design of hardware like ARM chips. That is an objectively terrible outcome.
You can of course quibble with such a statement, based on a rigid application of a simplistic set of definitions. But you'd do better to try to understand the truth conveyed by such a statement.
1 + '2'
1 - '2'
Number.MAX_SAFE_INTEGER + 2
and entire WAT series, stems from "don't raise" ethos. JavaScript exposes constructor instead of prototype that messed up a lot, in Ruby terms Object.alias_method :__proto__, :class
Object = Object.instance_method(:initialize)
Class = Class.instance_method(:initialize)
Class.__proto__.alias_method :prototype, :owner
new = ->(constructor) { constructor.owner.new }
Person = Class.prototype.new do
def initialize
end
end.instance_method(:initialize)
def Person.foo
'foo'
end
puts Person.foo
john = new.call Person
def john.bar
'bar'
end
puts john.bar
def (Person.prototype).baz
'baz'
end
puts john.__proto__.baz
Does anyone wants to adopt this feature in their language?If you could only choose one number type, would it be floats or ints? Crockford would say decimal, but the rest of use using commodity hardware would choose floats every time. It's not the language implement's fault someone doesn't understand IEEE 854. This max safe integer issue exists in ALL languages that use IEEE 854. In any case, BigInt is already in browsers and will be added to the spec shortly.
1 + "2"
#3
1 - "2"
#-1
1 . "2" | 1 .. "2"
#"12"
1 . "-2" | 1 .. "-2"
#"1-2"
Python and Ruby throw exception, use explicit type conversion and string interpolation 1 + '2'
Traceback (most recent call last):
TypeError (String can't be coerced into Integer)
1 + '2'.to_i
#3
"1#{'2'}"
#"12"
Hardly any language is perfect, I have not encounter much of operator overload in ruby (nokogiri?) but I believe C++ got it bad.One number type in Lua:
> 0 | 0xffffffff
4294967295
> 0 | 0xffffffffffffffff
-1
> 0 | 0x7fffffffffffffff
9223372036854775807
limited but better than JavaScript: 0 | 0xffffffff
//-1
BigInt is an improvement 0n | 0xffffffffn
//4294967295n
0xffffffffffffffffn
18446744073709551615n
it is strict 1n - "2"
1 + 1n
Uncaught TypeError: Cannot mix BigInt and other types, use explicit conversions
works nice with string interpolation: `${1n}`
"1"
Numbers is a sane example. One can argue it was for good. How about `{} + []`? I believe I can disable this part in JavaScript engine and no one would notice. And misleading `object[key]` where it calls toString, sure I have not tried that in a decade but it is stupid. UTF-16: ""[1] # there were emoji
//"�"
You've said nothing about constructor oriented programming. Unique feature, I have not heard any other language adopted it yet. The post you've replied contents sketch for Ruby. Actually I've got it wrong — every JavaScript function is a closure (Ruby method is not closure) and Prototype method was a class method (not instance method), fixed but ugly: def function(&block)
Class.prototype.new.tap do |c|
c.define_method(:initialize, block)
end.instance_method(:initialize)
end
def function_(object, name, &block)
object.class_eval do
define_method(name, &block)
end
end
Person = function { |name|
@name = name
}
function_(Person.prototype, :name_) {
@name
}
john = new.call Person, 'john'
puts john.__proto__ == Person.prototype
puts john.name_
def function__(object, name, &block)
object.singleton_class.class_eval do
define_method(name, &block)
end
end
function__(john, :name__) {
@name
}
puts john.name__
By the way, you can say "Yes, I know JavaScript has some problems". It is not a secret, everyone knows.It really doesn't take a super-genius to code javascript simply, efficiently, and without errors. Funny that a lot of programmers that think they're very smart are the ones that either shit on javascript, or make a lot of stupid errors with it, or both.
As you say, that is a problem with any language and project with a revolving door of developers. Perhaps those companies should learn their lesson and hire at least one or two good, permanent senior devs to keep things on track.
Like always, the human factor outweighs almost everything else.
https://www.goodreads.com/quotes/12608-when-i-use-a-word-hum...
That whole conversation is quite interesting and perhaps this part can also be thought of as alluding to "prescriptivism versus descriptivism".
Descriptivism refers generally to describing how a community uses language, so the most common usages end up being the primary definitions. Once documented, these tend to become prescriptive.
In that context, a single author who uses a word in an unusual way would likely not have any impact on the descriptive or prescriptive definitions of that word, unless of course their usage becomes common.
Humpty was arguing for the benefits of using words in unusual ways, which potentially violates both prescriptivism and descriptivism.
Impressionistic use of words is one example of this, where the words used might convey a certain feeling, perhaps via their connotations, even though their literal definitions may not be exactly appropriate. This kind of usage is generally found in literature where language is being used as an artistic tool rather than a prosaic tool of communication.
tl;dr: my HN comments is a art