Live data from Hacker News

JavaScript Is Weird

jsisweird.com

371–380 of 383 posts

Re: JavaScript Is Weird

#371
post #352

Earlier quoted context omitted.

Hey so can I write a device driver in JavaScript and is it a good language for that? How about my dma controller and python? What am I reading here. Not a comp sci major eh? Pass me something by reference in JavaScript, please

What's your point, exactly? You can write a driver in practically any language. > Not a comp sci major eh? I guess you're a comp sci major.

I was a comp sci major.

Do you know what a Pointer is?

Do you know what passing by reference means?

Do you know what a heap allocation is vs pushing something into the stack?

Do you know what code and bss segments are and what they are for?

This is not about being right or wrong, I just can’t stand to watch total nonsense go unchallenged.

No, you cannot write a hardware device driver in a dynamic language, which is not to preclude code generation approaches, but to point out what low level hardware programming actually consists of: manipulating memory, registers included

Re: JavaScript Is Weird

#372

Earlier quoted context omitted.

Sure, we can go into very true, but specific cases. But in a day to day usage: When you're writing plain JS, you have to do extra work to get type checks. When you're writing plain C, you have to use an unusual environment to not get basic type checks.

So? The majority of the business world does their desktop computing with Microsoft Windows, but it doesn't mean you have to. The same principle applies here. If you don't like your environment, fix it. Choosing not to and then complaining about the result makes little sense.

You don't control the whole environment. You'll likely use some libraries where people didn't use type checkers and wrote libraries in a complicated enough way that the analysis cannot give you an answer. This is where you control some of your environment and fixing it involves forking dependencies and more maintenance burden if you really do want to do it.

In this case, complaining about the environment as a whole does make sense.

Re: JavaScript Is Weird

#373
post #308

Earlier quoted context omitted.

Although I like Javascript (Typescript) a lot, I have to bite: > Dynamic languages are easier to program in. Only if you don't care about writing correct and maintainable programs. The only thing that dynamic languages make easier is writing code. Or, more specifically, the first couple of versions of it. That's not what typical programming as a process mostly consists of.

By the definition of formally correct, yes, you’re right. But dynamic programming still allows programs to be functionally correct, and verified by testing, which is more often than not good enough.

Writing and maintaining a program in a statically typed language is significantly easier and faster than doing the same in a dynamic language while manually writing all the tests that would cover the same level of correctness that types give you out of the box.

Re: JavaScript Is Weird

#374

Earlier quoted context omitted.

> Can it be that JS is not good starting language then? @ozim, I don't believe you are trolling! JS is an absolutely awful language for beginners; it's a 155mm howitzer pointed at your foot. Although you can get the hang of the basics quickly, AND it runs in the browser (super-convenient unless you're headless), those "basics" that you thought you'd got the hang of turn out to have semantics that make sense, but are…

Having designed programming curriculum, I have to disagree that the language is a bad language for beginners (though it is very far from ideal). To be fair the primary reason is not really a virtue of Javascript per se, but the fact that it runs in the browser is a large pedagogical gain that no other language can easily match and is hard to overstate. Learning to program is overwhelming for most students, and settin…

For starters it is maybe great, but I see problem with types that are not explained but create problems when building something more. Because in the end `var` is not just a bucket and adding strings to number bites people.

It is like learning how to snowboard, I am now on a level where I can go downhill quite quickly, but I don't have enough experience to not crash if something unexpected pops up.

Learning with `var` is just a bucket seems to be that it is going to cause a lot of frustration and pain later on when person thinks he gets it.

Re: JavaScript Is Weird

#375

Earlier quoted context omitted.

Having the full number stack supported (natural numbers - integers - rationals - reals) would be, indeed, awesome. Sadly, most people don't understand the distinctions, so this will never happen. (Even in reply to your post people keep talking about "decimals", as if the number base is at all relevant here.)

> reals This is technically impossible. Almost all of the real numbers can't be represented in a computer. The most you can get is the computable reals. But to be able to represent some of those and to do arithmetic on them, you have to use somewhat complicated representations such as Cauchy sequences. The use cases for computing with exact representations of (computable) irrational numbers are fairly limited (probab…

> This is technically impossible.

It's technically impossible for the integers too.

> Almost all of the real numbers can't be represented in a computer.

Almost all of the integers can't be represented in a computer.

What, exactly, is your point?

Re: JavaScript Is Weird

#376

Earlier quoted context omitted.

> reals This is technically impossible. Almost all of the real numbers can't be represented in a computer. The most you can get is the computable reals. But to be able to represent some of those and to do arithmetic on them, you have to use somewhat complicated representations such as Cauchy sequences. The use cases for computing with exact representations of (computable) irrational numbers are fairly limited (probab…

> This is technically impossible. It's technically impossible for the integers too. > Almost all of the real numbers can't be represented in a computer. Almost all of the integers can't be represented in a computer. What, exactly, is your point?

These two things are not alike.

For every integer, there exists a computer that can represent it. Even with constant memory, I can right now write a computer program that will eventually output every integer if it runs for long enough.

By contrast, for almost all (i.e. an uncountable number of) real numbers there exists no computer whatsoever that can ever hope to represent any of them.

Another way of seeing that is that, while Z is infinite, any single integer only requires finite amount of memory. But a real number may require an infinite amount of memory.

The integers can also be represented fairly easily as a type. For the naturals, for example, it's as easy as

  data Nat = Z | S Nat
(ML-type languages allow to do this very concisely, but you can do theoretically the same type of thing with e.g. Java and inheritance; if you use Scala or Kotlin, use a sealed class, if you use Swift, use an enum, etc.)

The integers are slightly more complicated (if you just try to add a sign, you'll have to deal with the fact that you now have +0 and -0), but still not hard. Rationals are a bit harder in that now you really have multiple different representations which are equivalent, but you can also deal with that.

By contrast, you won't be able to construct a type that encodes exactly the set of real numbers. The most you can do is to provide e.g. an interface (or typeclass) Real with some associated axioms and let any concrete type implement that interface.

Re: JavaScript Is Weird

#377

Earlier quoted context omitted.

> This is technically impossible. It's technically impossible for the integers too. > Almost all of the real numbers can't be represented in a computer. Almost all of the integers can't be represented in a computer. What, exactly, is your point?

These two things are not alike. For every integer, there exists a computer that can represent it. Even with constant memory, I can right now write a computer program that will eventually output every integer if it runs for long enough. By contrast, for almost all (i.e. an uncountable number of) real numbers there exists no computer whatsoever that can ever hope to represent any of them. Another way of seeing that is…

You're trying to explain the difference between countable and uncountable infinities here.

The distinction is irrelevant in the context of computers.

> By contrast, you won't be able to construct a type that encodes exactly the set of real numbers.

You don't need to encode exactly, just like you don't need to encode the integers "exactly".

All you need is a way to guarantee a finite number of significant digits in your real number approximation.

Floating point numbers give you that, problem solved.

Re: JavaScript Is Weird

#378

Earlier quoted context omitted.

These two things are not alike. For every integer, there exists a computer that can represent it. Even with constant memory, I can right now write a computer program that will eventually output every integer if it runs for long enough. By contrast, for almost all (i.e. an uncountable number of) real numbers there exists no computer whatsoever that can ever hope to represent any of them. Another way of seeing that is…

You're trying to explain the difference between countable and uncountable infinities here. The distinction is irrelevant in the context of computers. > By contrast, you won't be able to construct a type that encodes exactly the set of real numbers. You don't need to encode exactly , just like you don't need to encode the integers "exactly". All you need is a way to guarantee a finite number of significant digits in y…

> Floating point numbers give you that, problem solved.

No. For example, floating point addition is not necessarily associative. In that sense, floating point numbers aren't even a field and it's wrong to say that they can be used as a stand-in for real numbers.

Floating-point numbers are incredibly useful and it is amazing that we can exactly analyze their error bounds, but it's wrong to treat them as if they were real numbers.

Re: JavaScript Is Weird

#379

Earlier quoted context omitted.

If the good lord had wanted us to interact with transistors based on mnemonics, not electrical currents, he'd have implemented our brains in mnemonics, not electrical currents.

Nitpick: voltage potentials and ion channels. There's not much actual current flowing.

Nitpick over nitpick: synapses are not exactly electrical or ion current based, they have active transporters.

If all electrical activity ceases, does memory survive? (Answer is very likely yes given cryonic experiments. Brain is protein, ion currents have tendency to auto fire on defrost.)

Re: JavaScript Is Weird

#380
post #365

Earlier quoted context omitted.

> It is NOT good as a high-volume web server, for example You couldn’t have picked a worse example - your CS major seems to be needing a refresh. NodeJS came to be precisely because V8, single threaded and using an event loop, was GREAT at a high volume web servers. It massively reduced the overhead vs multi-process or thread based web servers and absolutely dominated performance benchmarks and concurrency. We starte…

1) you confuse me with a CS major on another thread. pick the right feud please. 2) "you couldn't have picked a worse example" HAAAA! You are wrong. wrong wrong. A) Do you even know what a memory leak IS and why/how it occurs? B) Did you understand what I said regarding stack allocation and out-of-scope equals "memory gone" and how that fundamentally differs from heap-based allocation as ALL JS OBJECTS ARE!??? you ar…

Wait, where do memory leaks come in and what the hell fo they have to do with the subject at hand? I was talking about it’s fit for web servers, not embedded development. I’m disputing very specific comments you have made. You completely ignored what I said, and now accuse me of “copying marketing lines” and not knowing what an event loop is? Really? Is this how you win arguments?

I don’t know what you’re excited about yelling in caps - VertX uses and event loop. Goroutines are cooperative scheduling. Yes, they can also coordinate over multiple threads (guess what, node can too) but the underlying architecture for processing requests is the same.

> Node JS is a terrible high-volume web server

Again, why would that be? Node was invented precisely to be a high performance server. It’s literally it’s purpose, and it delivers. Check out any benchmarks like TechEmpower and guess which platforms you’ll find near the top. I’m not saying it’s the best choice but just stating facts. Nothing else to say here - you obviously have strong opinions but zero hands-on knowledge on this area.

Post reply on HN