Hacker Newsnew | past | comments | ask | show | jobs | submit | zanethomas's commentslogin

I know, right?

Fortunately we can still aren't forced to use all the 'enhancements'.


I don't understand the need for the ever-growing list of "enhancements" to JS. Take Class for example.

Class is entirely unnecessary and, essentially, tries to turn JS into a class-oriented language from its core which is object-oriented.

I never create classes. I always create factory functions which, when appropriate, can accept other objects for composition.

And I don't use prototypes, because they are unnecessary as well. Thus sparing me the inconvenience, and potential issues, of using 'this'.

In my dreams those who want to turn JS into c# or Java should just create a language they like and stop piling on to JS.

But, at least so far, the core of JS has not been ruined.

That said, there are some new features I like. Promises/async/await, Map, Set, enhancements to Array being among them. But to my way of thinking they do not change the nature of the language in any way.


Otoh, I create classes, use prototypes and it’s natural and useful in many of my cases.

In my dreams those who want to turn JS into c# or Java should just create a language they like and stop piling on to JS.

We could even share this dream if browser vendors weren’t such whos the boss iam da boss when it comes to extensions and alternatives. So we have to live in a common denominator, which surprisingly isn’t as bad as it could be, really.


I wonder why it seems natural to you? I'm guessing JS wasn't your first language and you didn't learn the power of composition instead of classes.


Because I think in objects (non-strictly related groups of data and methods) and it’s natural to how my business processes work. Light OOP creates neither translation nor maintenance layers to it. See https://news.ycombinator.com/item?id=41808034

I'm guessing JS wasn't your first language

Good intuition. My first language was basic, 8080 asm, x86 asm, pascal, C, perl, python, haskell (most useless), lua, objc. Js/ts is only a recent addition, so I might have missed some fashion ideas.

Tongue in cheek aside, if you’re an old dev, there’s nothing you have to listen to because you can see whether you have a problem yourself and decide for yourself. You can be your own advisor. I see both “classes” and “just functions” ways clearly and can convert my current codebases in my mind between these two. Nothing really changes for the latter, apart from bulky import sections, lots of * as ident imports, context-arg passing and few dispatch points. Objects (non-strictly related groups of data and methods) still exist and hold refs to event/callback emitters. So my reasoning isn’t why, my reasoning is why not. I have a tool, I have a business logic, pen pineapple apple pen. Don’t overthink it is my main principle.

Do I need to introduce composition? Do I have it already? How is it better than what I’m doing? Is it? What am I missing? What are they missing? What if they don’t? What if we speak of different things? These are the questions of a restless butt that cannot find rest on any stool. Instead it should ask: Do I have a problem?


:)

I started with 6800 machine language. Then c, smalltalk, scheme and etc.

Rather than spend a lot of time and botch a comparison between classes and factory functions I'll link you to an article.

He went further, introducing something he calls stamps, but I found them to be awkward the only time I tried to use them.

https://medium.com/javascript-scene/javascript-factory-funct...


Thanks, this added to my standard low-level experiments in a new language. The most interesting (or should I say well thought-through and at the same time tricky) part of js is how prototypes and properties work. Rarely a language has a similar complexity at that level, but I started to respect it the second I’ve got an overview, cause it addresses well the pain points that simpler designs usually have.

That said, for me it’s hard to buy into his arguments, in a sense that it doesn’t matter that much, if at all. instanceof doesn’t work for different realms and is nuanced for direct prototyping and Object.create(), but I never use or care about these in my code, by design. There’s no way that such value could appear in a false-negative instanceof comparison, so. A similar thing happens in COM/OLE integrated runtimes, where you have to be careful with what quacks like a date or a string but is neither due to a wrapper. But that’s expected.

I believe the real issue here is that iframes/etc usually get served as “some values aren’t, so use X, be careful” rather than “guys it’s an effing wrapper to an effing different runtime, which we found to be an overall anti-pattern many years ago”. Browsers and webguys normalized it, well, they normalized many crazy stuff. Not my problem. There’s no need to learn to balance on two chairs when it’s not what you do when sober. I still use Array.isArray(), but only because every linter out there annoys you to hell into it.

Tldr: classes are neat you can pry them from my cold dead hands.

The only thing to care about with classes is to not fall into the inheritance trap, and not for the reasons of instanceof. Inheritance is a tree of ladders attached with a duct tape, you have to know what you’re trying to do to your design before thinking about it. Most sane use of inheritance is one-off from a library to a user (two separate developing agents agree on an implied behavior, “I implemented it for you to randomly extend and pass back” mode), or for helping type inference. Otherwise, a way to go is to eject a common behavior into a separate class or a couple of functions (aka composition).


Fair points. I do use classes exposed by libraries. I don't like it but it beats the alternative.

I really like the flexibility of factory functions, that is the main point of the article imo.

COM/OLE ... that takes me back to the early 90s, a place I hoped to never visit again!

:)


Hello JS was my first language and I use classes because sometimes it seems like the obvious way to model things.

Looking through the source of Replicache, here are some classes we use:

- KVStore

- DAGStore

- Transaction

I mean ... I can of course model these w/o classes, but encapsulating the state and methods together feels right to me. Especially when there is private state that only the methods should manipulate.

We use composition all over the place and rarely use inheritance so I don't think it's just some deficiency of knowledge .

Pre JS classes, the js community emulated classes w/ the prototype chain and that's what I'd have done for these classes if real JS classes weren't available.


closures can encapsulate state and methods classes are syntactic sugar

emulating classes is, imo, exactly the problem

using factory functions which create and return an object, with variables passed to and created in the function, handles encapsulation

and there is no `this` to deal with


Honestly, all this “emulated with prototypes” meme is misleading. Prototypes are an implementation of what they’ve called “binding” before (some may recognize “early” and “late” in this context). That’s how classes work and what classes are. The fact that some gears got exposed to a user [to stick their fingers into] doesn’t change much.

So no, javascript didn’t really “add classes”. It just had a very annoying lower-level syntax for them from the beginning and fixed it after a while. It wouldn’t survive the pressure if it had no classes at all cause this idea is fundamental to programming and to how we think: you-do.

One may pretend to not have classes through closures, but technically that’s just classes again, cause you have a bunch of functions with a shared upvalue block. You just hold it the other way round lexically, by a method instead of a context.

I believe this common idea of alienating classes stems from the general OOP stigma since the times of “design patterns”.


Classes generally point you towards writing more performant code. Factory functions allow you to achieve the same performance, you just have to be a bit more careful not to cause a depot :)

For example,

1. field declarations [1] make sure that the fields are always initialized in the same order. That way most of your functions end up monomorphic, instead of being polymorphic [2]

2. Method declarations are also (almost) free, since you only pay for them once, during class initialization.

You also get a few other niceties such as private properties. You can emulate private properties with closures in factory functions but V8 has a hard time optimizing, unfortunately.

---

[1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

[2]: https://www.builder.io/blog/monomorphic-javascript


The difference in performance is negligible for all but the most demanding applications. In which case I would still use factory functions, but just be more careful.


I agree. But it's one reason why someone who is concerned about performance, may prefer classes by default.


I like JS's flexibility too, but I have to point out that your object-oriented JS code is compiled into C++ classes by the v8 optimizer! (Unless you change their structure, in which case it gives up (deoptimization).)


Does it compile something like this into a c++ class?

makeThing(options, usethistoo) { let foo = options.foo; let thistoo = usethistoo;

  return {
    functions...
  }
}


I'm not sure if "C++ class" is the right term, but it will certainly compile into a class behind the scenes [1]

You can use d8 to check what the class structure ends up looking like [2]

---

[1]: https://v8.dev/docs/hidden-classes

[2]: https://v8.dev/docs/d8


>And I don't use prototypes, because they are unnecessary as well. Thus sparing me the inconvenience, and potential issues, of using 'this'.

Eh, prototypes share, instead of create, method references. I guess you can use delegate objects too though unless you're just doing pure functions.


Sure, but imo unless one is creating very many objects each with their own set of functions it's not really a significant issue.

Sometimes programmers spend way too much time optimizing code which doesn't really need it.

In my experience how data is structured is almost always the most important factor when it comes to performance.

Good data structure + simple code === performance.


The web became trashed over a decade ago.


The web became trashed over a decade ago.


Because they chose it as a career and not because they love it?


Isn't that Google's original algorithm?


PageRank is. This is a modification of PageRank. The original algorithm calculates the eigenvector of the link graph.

This algorithm uses the same method to calculate an eigenvector in an embedding space based on the similarity of the incident vectors of the link graph.


Hmmm, odd. I was under the impression they used cosine similarity based on page content. Once upon a time, based on that 'memory', I created a system to bin domain names into categories using cosine similarity. It worked surprising well.

Regardless, well done!


Hmm, seems like something that might be used for deduplication maybe?


Don't use it, don't care.


I knew a woman who in 1970 was pulled over by the police in Altadena CA. They were particularly aggressive when it came to "hippies" and so she swallowed her entire cargo of LSD, which was, iirc, somewhere in the neighborhood of 20 hits.

She was out of commission for roughly 72 hours and months later still not back to normal, according to what she told me.


One of my favorite early blog stories is from stilldrinking.org, where he accidentally ingested way too much and ended up institutionalized. It's great writing about the entire experience going there and back. http://www.stilldrinking.org/the-episode-part-1


I first read this a few years ago, it's great. Haven't seen it since and had no idea how to find it, thanks for posting!


is the code on github? if not i'm not going to touch it :)


strange that a constitutional amendment was required to ban alcohol, but none was required for other drugs


It wouldn’t require an amendment today. Sadly the courts have supported a huge increase in the federal government’s police power over the years.


It didn't require an amendment in the past either.


The Supreme Court could have chosen not to interpret the Commerce Clause so broadly to say that not engaging in interstate commerce affects interstate commerce and therefore counts as interstate commerce (IIRC that started with wheat, not drugs), in which case most federal drug laws would not apply unless the activity actually involved interstate commerce. Then an amendment would be needed.


Yes, had things been different they would have been different. I'm not sure what the point of that statement is, honestly.


I don't think an amendment was required. Alcohol could have been banned at the time through legislation, it just would have been easier to reverse and maybe less universal.


That’s not correct as far as I understand it. Prior to Wickard v. Filburn the federal government did not have the power to ban substances (since it isn’t explicitly specified in the constitution). If congress had passed a law doing so, that law would have been considered unconstitutional. Wickard v. Filburn is obviously ridiculous and should be overturned, but it never will be.


The way I interpret a decision like that is the court saying "yes the government does have the power to do this and it always has, it is specified in the constitution and if you thought otherwise you've been reading it wrong." It's sort of a pointless philosophical distinction, but I wouldn't say the government didn't have that power before the decision, I'd say they did but they never tried to use it (unless the court was overturning a previous decision).

I'm aware that the Supreme Court sometimes completely changes its mind in a matter of decades, so it's possible a legislative prohibition would have been struck down 20 years before Wickard v. Filburn, but it's also possible the court would have come to the same unanimous decision. I don't know anything about legal history so if there's some obvious reason the 1918 court would have ruled differently then I apologize.


> The way I interpret a decision like that is the court saying "yes the government does have the power to do this and it always has, it is specified in the constitution and if you thought otherwise you've been reading it wrong."

That is indeed the theory but it’s completely fictional.


The amendment was a goal by prohibitionists to ensure the law wouldn't be easily repealed. To their chagrin, they didn't realize the will of the people in banning their ridiculous amendment.


Prohibition obviously reflected the will of the people—it’s impossible to amend the constitution without supermajority support. The Volstead Act was approved by overwhelming majorities of both houses, and then ratified by 46 of 48 states.

It wasn’t “ridiculous.” It was one of the first things women did with the vote. It probably would’ve worked if it hadn’t been for Irish and Italian immigrants.


I think there's more to it than "immigrants love their alcohol so much they started whole criminal enterprises." It's probably coincidental that the biggest names in illicit alcohol during that era happened to be Italian crime family names.

In the south there were so many bootleggers that they used to race each other around tracks to see who had the fastest car. This would eventually become Nascar.

I think it's more accurate to say that there was overwhelming support for Volstead from people in power who were swayed by the narrative that alcohol was draining families of resources and dis-inhibiting otherwise good men from hitting their wives and children. But there were also a lot of people who didn't let alcohol ruin their marriages and family relationships, and those people would eventually get the act repealed.


Prohibition wasn’t repealed because we determined “alcohol isn’t so bad.” To this day, alcohol remains tremendously damaging to women. 70% of sexual assaults involve alcohol use by the perpetrator. 55% of domestic violence incidents involve alcohol use prior to the incident. Obviously that doesn’t exculpate the perpetrators. But those bad people will exist no matter what—alcohol pours fuel on the fire.

We repealed prohibition because it proved unenforceable. And Irish and Italian immigrants had a tremendous amount to do with that, both because of their participation in organized crime and because of their cultural acceptance of alcohol. (To this day, the divide between people who supported temperance and those who got it repealed lives on in who serves grape juice at communion and who serves wine. Even a century of integration later, there’s a marked difference between evangelical Protestants and Catholics in terms of regular alcohol use.)

After all, it’s not like banning alcohol is impossible. Alcohol use is extremely restricted in many countries around the world.


Is German or English beer culture new? They may be culturally less prone to skirting the law than Irish or Italians (want to stress the word culturally here), but I don’t really see how we can attribute it to a cultural difference in the acceptance of alcohol.


Temperance was an outgrowth of religious movements that occurred within American Protestantism in the late 1700s and through the 1800s: https://en.wikipedia.org/wiki/Temperance_movement. The seeds of this were sown back in Europe (John Wellesley for example) but those groups like Baptists, Methodists, and Quakers who opposed alcohol (and still do) had a lot more influence in America than they did back in Europe. And since the country was new they had a greater ability to reshape the culture.

So the relevant cultural difference is between these American Protestants, who had been diverging from Europe for 100+ years, and immigrants from continental Europe, who hadn’t experienced that cultural change.


Speaking of Appalachian bootleggers, my great grandpa was one. There are ruins far in the woods outside my childhood home when you can see the old infrastructure and a pile of rusty cans that used to be 10 ft high. It's mostly disintegrated now. My great grandpa retired from it when he was visited by some rival Italians who wanted to have exclusive access to him. He was offered the choice to retire or serve them exclusively so he gave up the business and went back to farming.


Everyone reading this who isn’t familiar with Wickard v. Filburn please look it up on Wikipedia. Greater awareness of it would be really helpful. It is a blatantly insane interpretation and a huge amount of power at the federal level is built on top of it.


Even if you don't enjoy that interpretation of

"To regulate commerce with foreign nations, and among the several states, and with the Indian tribes;"

You cannot deny that "among the several states" can be interpreted to mean congress can regulate commerce in the states.


I’m not sure what you mean? I think that pretty clearly refers to commerce between states. How are you interpreting it differently? They just really casually and implicitly gave the feds the power to regulate all interpersonal transactions within each state? I think they would have said that explicitly if they meant it, no?


"Among the several states" does not conclusively disallow congress from regulating intrastate commerce in my opinion. How does "among" restrict the regulation only to things going between the states? What definition of "among" limits the rest of the clause to only certain interactions involving commerce flowing through multiple of the states?

If I regulate commerce specifically in the state of Virginia, which is a member of the set of states, IMO I am regulating commerce among the states. The rest of that section of the constitution is all about how the Government's laws should be equal across all states, ie there is no favoritism, so that also leads me to believe this could be about keeping the government fair, rather than limited.

Keep in mind a huge point of the Constitution superseding the articles of confederation was that interstate activities were a pain in the ass and trade treaties were a dumpster fire. Giving congress final say over trade in the Union is absolutely compatible with that. It was not a document about keeping the Feds out of the business of the states. It was entirely about giving the federal government MORE power over the affairs of the states because the previous federal government was basically useless and at the whims of powerful state governors who absolutely did not want to stop being the kings of their little fiefdoms.


It was not and is not required! Many states and locations locally banned alcohol before and after prohibition. What did take a constitutional amendment was ending prohibition but only because it was implemented through a constitutional amedment.


It took a constitutional amendment to do it at the federal level. Congress would not have been able to pass such a law constitutionally prior to Wickard v. Filburn.


Alcohol was used by more people. The governmental play that had to be carried out to make the people tolerate the tyranny was minimal.

Remember it’s not about what a piece of paper says the rules are - it’s what you can get away with in power.


They weren't bans originally. They were huge taxes that nobody could afford to pay. The bans came later after the supremes gave carte blanche to the feds.


It wasn't required. It was a moonshot that worked.


We used to be a republic, now we are a democracy.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: