5
v00d0
6y

I fucking hate that in JavaScript we have the naming convention of index.js for entry points, whyyy? no sense, thanks node

Comments
  • 14
    It simplifies includes/requires:

    `require Bar from "components/Foo/Bar"`
    `require Qux from "components/Qux"

    This allows you to have assets/subcomponents organized nicely without having to specify "Qux.js" every time.

    "index" is a little odd, but it is already widely understood and accepted as standard practice. What would you suggest instead?
  • 8
    @Root is right, It works like (and probably comes from) the index.html used for decades. But I don't see any situation where this is mandatory, everytime I saw it, it was configurable.
    In components I often use index.js, but for the application level entry point I stick to app.js or even main.js.
  • 4
    __init__.js ? :D
  • 4
    @alesg oh, python naming conventions are the worst
  • 0
    Ye it's useful but i mean, why index? It's a bit misleading
  • 0
    @v00d0 convention

    As @lucaspar already said: index.html has been used basically since the www first appeared, people are familiar with it and know what to do with it right away
  • 0
    @Krokoklemme js this days is not only web it's anywhere, so it has no sense having index as convention. Based on your thoughts even python, elixir, go etc. should have it. In my opinion Is not convention is just a fact... and we accepted it as good only because the creator of node decided so.
Add Comment