News for hackers. Stuff that matters.
Re:W3schools.dev Redirects to Mozilla Developer Network by teddyh on Friday March 01, 2019 @09:40AM (#19280989)
W3Schools also used to be quite bad and misleading; this is an old page with a huge list of problems with W3Schools:

https://web.archive.org/web/20110117085131/http://w3fools.co...

Re:W3schools.dev Redirects to Mozilla Developer Network by onli on Friday March 01, 2019 @09:49AM (#19281087)
Used to is the important word here. They improved a lot.

I like them. MDN is great, but w3schools is better in giving examples on how to use stuff.

Re:W3schools.dev Redirects to Mozilla Developer Network by NeedMoreTea on Friday March 01, 2019 @11:51AM (#19282570)
It's a little like GoDaddy, or Facebook.

W3schools were so bad, essentially just a click farm promoting any old crap for the pageview, that it'll take a huge amount of correcting, improving, and newly found ethical standards to let me forgive them. Or forget there really was a need for w3fools. They always gave lots of examples, and they were often simply wrong.

Even when they apparently have the answer, until I can validate it on SO or some other place, I'll tend to not trusting...

Re:W3schools.dev Redirects to Mozilla Developer Network by kevinsimper on Friday March 01, 2019 @11:23AM (#19282180)
I tried adding better examples for "alert"s for example, but my PR got not approved because it didn't fit the exact structure of how the wiki is structured. So they make it intentionally worse than w3schools :)

https://github.com/mdn/interactive-examples/pull/1266

Re:W3schools.dev Redirects to Mozilla Developer Network by TheRealPomax on Friday March 01, 2019 @11:35AM (#19282355)
<h1>how to use alert()</h1>

<p>see the Console API</p>

<footer>don't use alert(), don't talk about alert(), don't teach alert(), it's not 1997 anymore</footer>

Re:W3schools.dev Redirects to Mozilla Developer Network by sametmax on Friday March 01, 2019 @11:52AM (#19282576)
alert() is very handy to learn, as it gives the new commer something tangible and familiar to use for tests.

You just have to give proper context.

Re:W3schools.dev Redirects to Mozilla Developer Network by TheRealPomax on Tuesday March 05, 2019 @12:42AM (#19308369)
No, the console API is a handy thing to learn. Alert is not handy, it's an ancient function that (a) blocks your page thread, (b) can't show anything except `.valueOf`, (c) can't be selectively ignored, (d) it's an obsolete API from way back when javascript 1.5 was hot stuff.

If you're teaching, teach people to use console.log because that's where they're going to get REAL insight into what the code's doing (console.table you say? amazing!) and never look back. And if you're learning, demand people teach you modern practices. Not ridiculous things from 20 years ago.

Re:W3schools.dev Redirects to Mozilla Developer Network by jimsmart on Friday March 01, 2019 @12:39PM (#19283269)
> proper context.

That's not 'tests' — tests would be something like Mocha, or Jasmine — what you're actually talking about here is one of the many forms of ad hoc in-browser debugging.

Re:W3schools.dev Redirects to Mozilla Developer Network by yorwba on Friday March 01, 2019 @01:02PM (#19283554)
Automatic tests are not the only way to test software, nor are they sufficient. Whether some software can actually be used is not something that's completely formalizable and so you can't test it automatically. You always need a human in the loop in the end, and alert is a legitimate tool to effortlessly display some additional information on internal state during an interactive user test.
Re:W3schools.dev Redirects to Mozilla Developer Network by johnfn on Friday March 01, 2019 @01:08PM (#19283630)
> ad hoc in-browser debugging

Ah, if only there was a single word - a verb perhaps - that developers could use to colloquially refer to this process!

Re:W3schools.dev Redirects to Mozilla Developer Network by sametmax on Friday March 01, 2019 @02:58PM (#19284682)
Not testing the code, fidling with the stuff they are learning.
Re:W3schools.dev Redirects to Mozilla Developer Network by umanwizard on Friday March 01, 2019 @09:57AM (#19281166)
EDIT: It seems that Python lists are in fact arrays. Cool, so Python does in fact support arrays. Seems a pretty important fact to point out on a page called "Python Arrays".

Original comment:

There is still some complete nonsense on w3schools. For example, I wanted to know recently whether Python supports arrays. The first result on Google is this page: https://www.w3schools.com/python/python_arrays.asp

There is a small disclaimer at the top stating: "Note: Python does not have built-in support for Arrays, but Python Lists can be used instead."

Why the fuck is your page called "Python Arrays" if you don't plan to talk about arrays?

Then the rest of the page talks about lists, while erroneously calling them arrays, in complete defiance of the disclaimer. I imagine what happened is that someone who doesn't know what an array is wrote the page originally, then someone else came by later and realized it was wrong, but instead of actually fixing it, slapped that half-assed disclaimer on top.

I still don't know whether stock Python actually supports arrays. I ended up just importing Numpy.

Re:W3schools.dev Redirects to Mozilla Developer Network by scrollaway on Friday March 01, 2019 @10:08AM (#19281262)
"Array" is a pretty loosely defined term that varies from language to language. Python lists are what you may know as "variable-length arrays" of python objects (in other words: not type constrained). If you want type-constrained arrays, you'll use the array module: https://docs.python.org/3/library/array.html

that w3schools page is indeed nonsense. They should probably stick to JS.

Re:W3schools.dev Redirects to Mozilla Developer Network by geoelectric on Friday March 01, 2019 @01:20PM (#19283742)
It depends on how strictly one defines "array." If you mean it generically as "an indexable contiguous memory buffer containing the actual data being indexed," pretty sure Python lists don't comply even at a mechanical level.

While the Python 3 docs for arrays certainly do lean on the type-constraint, I notice it also has the various operations that imply a contiguous buffer (cast to bytes, etc.), so I wonder if that's not the real distinction and the type constraint serves that.

Traditional Python lists are much closer to what I know as a vector: indexable like an array, but dynamically expandable and usually implemented as a list of references to data structures instead of containing the data itself so allows for heterogenous data.

Informally, I've certainly called both types of things arrays, right or wrong, and rarely call anything a vector other than container classes by that name, but I do suspect that's what your parent comment is drilling on.

* Then there's the JS Array class, which acts more like a vector than array by those definitions, so who knows.

Re:W3schools.dev Redirects to Mozilla Developer Network by umanwizard on Friday March 01, 2019 @10:13AM (#19281310)
Python lists may well be implemented as arrays. I don't know if they are or not, as I haven't read the Python interpreter source code.

If they are, then the article is even worse, as the disclaimer that Python doesn't have arrays is a lie!

Re:W3schools.dev Redirects to Mozilla Developer Network by cferr on Friday March 01, 2019 @03:06PM (#19284752)
Everything in Python is implemented as a dict behind the scenes, which is implemented in C with a few different types. Python does have arrays in the standard library's array module, so yes saying python doesn't have arrays would be a lie.
Re:W3schools.dev Redirects to Mozilla Developer Network by onli on Friday March 01, 2019 @10:10AM (#19281283)
I'd be angry at python there. It's python that uses lists like arrays in the standard language, making beginners search for arrays when python would use a list.

That's a pattern of the language and why I don't like it: It's very often almost like the other C-like languages, only to be that much different that it gets confusing. To just ignore that and call a list an array is not correct, but it makes the beginner searching how to do array-like stuff in python succeed in his task.

I'd be more annoyed at that page if they didn't explain the situation, but they do.

Re:W3schools.dev Redirects to Mozilla Developer Network by umanwizard on Friday March 01, 2019 @10:20AM (#19281370)
> I'd be more annoyed at that page if they didn't explain the situation, but they do.

Actually, they don't. The article claims that arrays don't exist, but you can use lists instead.

Apparently the polar opposite is true: lists don't exist, but you can use arrays instead! (And they're called "lists" for whatever reason).

Re:W3schools.dev Redirects to Mozilla Developer Network by onli on Friday March 01, 2019 @10:58AM (#19281801)
Python has something it calls lists. Those lists are basically like what other languages would call arrays.

But python also has an array module you can use after an import, it's not loaded by default. That data structure behaves even more like the thing C calls an array.

I don't see why a python list is not a list per se. Don't be confused by the others explaining it is not a linked list - something does not have to be a linked list to be a list. It's still a numbered collection of stuff that can be sorted, thus a list.

Though it is true that as a programmer you probably are first confronted with a data structure called list when you learn a LISP, and that data structure will be a linked list.

Confronting beginners with all this is not useful for them, w3schools just adding a note and calling the python default collection thing an array is thus not that unreasonable. Though I'd prefer it if they just called it a list in the explanation below the note, after explaining that this list structure is what you are probably searching, with a link "look there for what python calls an array". So in that way I agree with you, this is not optimal.

Re:W3schools.dev Redirects to Mozilla Developer Network by Scarblac on Friday March 01, 2019 @10:29AM (#19281466)
This is silly. Both "list" and "array" are so broadly defined that they largely overlap.
Re:W3schools.dev Redirects to Mozilla Developer Network by umanwizard on Friday March 01, 2019 @10:34AM (#19281517)
Then why doesn’t the article point out what definitions it’s using, rather than claiming arrays don’t exist and then talking about arrays?
Re:W3schools.dev Redirects to Mozilla Developer Network by kennydude on Friday March 01, 2019 @10:02AM (#19281204)
Python lists do the job of an array probably for 99% of cases. Depends on your exact definition of an array and if that even matters
Re:W3schools.dev Redirects to Mozilla Developer Network by jerf on Friday March 01, 2019 @10:33AM (#19281510)
As always, as you say, it depends on your definition.

One of the useful definitions of an array is that it guarantees contiguous storage in memory. In Python, there is no way to guarantee that; even if a list is a C array of Python references under the hood, there's no way to store the information represented by those references contiguously in memory. From that perspective, pure Python doesn't have any arrays at all, which is precisely why the popular NumPy has to offer explicit support for numeric arrays.

From another perspective, arrays are a set of O() guarantees for various operations. From that perspective, Python lists will generally meet the specifications that you'd write for a resizable array, or perhaps what you might call "vector", depending. CPython comes with some awful constant factors but the O() of the lists will be what you'd expect.

Rather than arguing about whether Python has "arrays" interminably, it's better to carefully define array, then dispassionately examine Python lists to see if they match that definiton. You'll get a yes sometimes and no others. I say "dispassionately" because too many people seem to assign moral qualities to whether or not something conforms to a given definition, but that's not a path to understanding. No matter what definition you write down for "array", not a single characteristic of Python will change.

Re:W3schools.dev Redirects to Mozilla Developer Network by umanwizard on Friday March 01, 2019 @10:06AM (#19281243)
The subway does the job of a car in 99% of cases. Doesn't mean they're the same thing. I also wouldn't appreciate an article about subways with the title "Cars".

I have literally never seen or heard of a definition of array according to which lists are arrays -- can you cite one?

Re:W3schools.dev Redirects to Mozilla Developer Network by anisppp on Friday March 01, 2019 @10:15AM (#19281329)
Can you cite a common definition of “array” other than a bare minimum of being randomly accessible? (Nothing else is pinned down. Fixed vs variable length, single vs mixed type, or even underlying data structure (cf NSArray)).

By the only universal definition I can think of, python lists are arrays.

Python lists most certainly meet the mathematical definition of array (ie name by index)

Re:W3schools.dev Redirects to Mozilla Developer Network by umanwizard on Friday March 01, 2019 @10:18AM (#19281353)
It seems you're right. Python lists are arrays -- I didn't know that.

That makes my point even stronger. The article about "Python Arrays" directly claims that Python Arrays don't exist, which is apparently wrong!

The whole point is that I came away from the article believing information that is false.

Re:W3schools.dev Redirects to Mozilla Developer Network by ben509 on Friday March 01, 2019 @10:50AM (#19281709)
Arrays are commonly an implementation, while lists are the mathematical or logical structure.

Same as how a hashtable is used to implement a mapping.

Re:W3schools.dev Redirects to Mozilla Developer Network by proaralyst on Friday March 01, 2019 @10:12AM (#19281305)
Python lists are dynamic arrays, not linked lists.
Re:W3schools.dev Redirects to Mozilla Developer Network by umanwizard on Friday March 01, 2019 @10:13AM (#19281319)
Then why does the article incorrectly claim that Python doesn't support arrays?

The whole point of my comment is that I went away from the article still not knowing whether Python has arrays, or not. I can't understand how anyone would defend an article called "X" that doesn't even properly inform you whether X exists

Re:W3schools.dev Redirects to Mozilla Developer Network by deathanatos on Friday March 01, 2019 @10:51AM (#19281721)
The article is not even wrong. That first yellow highlight is … ugh.

If a programmer from another language asks for an array, I'm going to point them at the `list` class in Python.

As some other sub-comments under your original post note, some uses of an array want the actual data to be contiguous. But Python `list`'s values are references to other values, not the direct values themselves. If you're familiar w/ C, it's closer to an array of pointers to objects. That matters for some niche cases. But in basic tutorial? No. And Python has some built-in types to account for some of the niche cases. Sure, that pointer is not free, and the overhead of a Python object is not free, but Python is a high level scripting language, and generally, `list` provides a random-access ordered collection, which is what most people want when they say "array", and the overhead doesn't matter for many things.

Re:W3schools.dev Redirects to Mozilla Developer Network by ben509 on Friday March 01, 2019 @10:48AM (#19281687)
Python's list type is implemented as a dynamic array in CPython. This is not required.

An optimizing Python doing escape analysis could see a list was going to be converted to a set and swap in a set and change the method calls. Or it could see a large number of concatenations and use a linked list as an intermediate form.

Re:W3schools.dev Redirects to Mozilla Developer Network by teddyh on Friday March 01, 2019 @09:57AM (#19281164)
I would rather use a site which started with correct documentation and added examples over time, than use a site which started full of bad documentation and examples, and slowly got corrections over time.
Re:W3schools.dev Redirects to Mozilla Developer Network by bryanrasmussen on Friday March 01, 2019 @11:06AM (#19281929)
I never use W3Schools but I have to say that I sort of feel bad about that because as a policy thing perhaps one should use something that has improved on bad behavior to become good in order to reward the improvement.

Of course improvement without expectation of reward shows a higher moral stature, but it is a stature that is perhaps not to be expected, whereas improvement based on reward seems more likely to exist in our world - given studies of the matter.

Re:W3schools.dev Redirects to Mozilla Developer Network by onli on Friday March 01, 2019 @09:59AM (#19281180)
If you use the site after it got corrected the difference is nil :)
Re:W3schools.dev Redirects to Mozilla Developer Network by dharmab on Friday March 01, 2019 @10:20AM (#19281382)
W3Fools has updated their stance:

"Today, W3Schools has largely resolved these issues and addressed the majority of the undersigned developers' concerns. For many beginners, W3Schools has structured tutorials and playgrounds that offer a decent learning experience. Do keep in mind: a more complete education will certainly include MDN and other reputable resources."

https://www.w3fools.com/

Re:W3schools.dev Redirects to Mozilla Developer Network by kkarakk on Saturday March 02, 2019 @05:12AM (#19288566)
That webpage is why i stopped using w3schools back in college.v nostalgic