TheOdinProject / curriculum

The open curriculum for learning web development

Home Page:https://www.theodinproject.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Javascript Course: Constructors Are Bad For JavaScript should be removed from assignments

JackBogart opened this issue · comments

Checks

Describe your suggestion

Currently under the assignments section the following article is an assigned reading: https://tsherif.wordpress.com/2013/08/04/constructors-are-bad-for-javascript/

This article is, in my opinion, describing a problem that is a result of improper usage of prototypal inheritance. The point of this article isn't about improper prototype so the usage of it isn't meant to showcase problems, but comes from being outdated. When written Object.setPrototypeOf() didn't exist yet. In the previous lesson this function is how users are taught to set prototypes. Therefore the problem being shown isn't one that users following lessons would run into, and the outdated syntax serves as a trap to confuse inexperienced programmers.

Below is an example of a rewrite of the code used in the article, this uses principles from TOP and assigned MDN docs.

function X() {
	this.protoprop = 'protoprop';
}

// Create object.
function C() {
	X.call(this);
	this.cprop = 'cprop';
}
Object.setPrototypeOf(C.prototype, X.prototype);
function F() {
	X.call(this);
	this.fprop = 'fprop';
}
Object.setPrototypeOf(F.prototype, X.prototype);

This approach didn't have the same problems the article mentions, furthering my point that this article is outdated which is over a decade old. Upon searching this article's name in the discord I discovered many people had issues with this article as well.

My suggestion would be to remove this from the assignments as it seems to only create more confusion than it does to educate users, or possibly replacing this article with a more up-to-date resource that accomplishes the same goal.

Path

Node / JS

Lesson Url

https://www.theodinproject.com/lessons/node-path-javascript-factory-functions-and-the-module-pattern#why-not-constructors

(Optional) Discord Name

No response

(Optional) Additional Comments

No response

commented

Thanks for the suggestion @JackBogart

@TheOdinProject/javascript can we get your thoughts on this one please?

Going through all these again, I'm currently of the mind that we could probably drop the article in question from the lesson entirely.
While the problem it's demonstrating isn't quite the same as the rewrite in the issue proposal, it's still a problem that people would be unlikely to run into IMHO (at least at this point), especially when it involves doing stuff that the constructor lesson explicitly says should not be done, in favour of the current ways to properly deal with prototype manipulation.

The main point of the article I feel is actually less about constructors themselves and more a grievance at how instanceof works (which is a very fair point given that the actual mechanism isn't really what you'd think, unlike with how it works in other languages).
Given that, I'm not sure we need this article specifically just to put that point across and demonstrate factory functions. The main lesson contents already has a section mentioning the issue with instanceof. So I'm not convinced this article provides substantial benefit. I'd also agree with what I've seen in the Discord community - this sort of article often does bring either more confusion, or even concern that they shouldn't be using constructors or classes at all because they're "bad bad taboo".

I'm personally in favour of just dropping the article from the lesson. Would appreciate any other insights of course.

I've been thinking about what @MaoShizhong said about this article being moreso about how instanceof works. Despite the lesson contents mentioning the issue with instanceof it is quite brief with barely any emphasis put on it, perhaps that was intended and this article was supposed to expand on it.

If this article is dropped (which I'm still in favor of), maybe it would be a good idea to briefly expand upon the instanceof section with a short example using the updated syntax taught in the previous lesson.

I'm not so sure the lesson needs to expand much on instanceof beyond what it currently has:

  • The focus of the lesson is and should be on factory functions
  • The lesson already highlights that instanceof checks the entire prototype chain and says how that doesn't actually mean the instance was constructed by the thing you're checking.

Personally, I think we can simply remove the one article in question from the assignment and that's it. I agree that it's caused more confusion than has been of benefit, and I can't see us getting a huge amount of benefit trying to do something else with it. I think the lesson without that article serves its purpose well enough.

Since you haven't checked the assignment box @JackBogart, I'm opening this up for assignment if someone wishes to comment below requesting assignment. Let me know if you wish to be assigned to this.

Acceptance criteria

  • Remove assignment 2 ("Tarek Sherif's article...") from the JS factory functions lesson assignment
commented

Hey @MaoShizhong, you can assign it to me :)