Replies: 6 comments 10 replies
-
I really like the naming changes. Previously, you had your svelte file: Now you just add a The projects I'm working with now are pretty small, so it makes total sense to put the logic right next to the page, and it makes it very clear what the different parts are doing, and in what order they're doing it. Another pro is that making every route a directory makes it really easy to add sub routes later without having to deal with a bunch of refactoring. |
Beta Was this translation helpful? Give feedback.
-
As someone being vocal in the discussions today and in the "I just hate it and it's ugly" for the + camp, I will take the bait. Nothing but respect for everyone. I'm glad we can have these discussions. TLDR; "There are only two hard things in Computer Science: cache invalidation and naming things." -- Phil Karlton
The thing though, the index comes from index.html. This has been around since the beginning of HTML. The convention was born with HTML. Then if we look at the next progression of the web, we have index.php. So JS didn't invent this convention, it was passed down. React & Angular picked up these conventions, which naturally lead to Svelte having it as well. But whether we call something index or page is irrelevant. Only pointing out that index has a long tradition.
In life and in computer science especially, you should follow convention unless you have an extremely compelling reason to go against it. To do otherwise is hubris; that you know better than the many brilliant people who came before. Usually, there are very good reasons why something wasn't done before. Change in itself is not a virtue. And does not automatically lead to innovation. Many times it makes things much worse. Especially when so many people have had a visceral response to the change. So is it because people don't want change, it happened too fast or that the reasons aren't extremely compelling?
So this is another convention that SK borrowed from PHP, Ruby & Python. In Ruby & Python, you would use __ FILE __ and in PHP it was used for magic functions. C+ reserves __ for the compiler's. _ has commonly been used in computer science for file names, data fields, spaces, italics in markdown in or to designate private. It's a natural fit in programming.
For starters, literally the docs say about the + is "Each route directory contains one or more route files, which can be identified by their + prefix.". So if nothing else, the docs need to be way more explicit and clear. Secondly, this is induced friction. Sveltekit is the underdog here. In an extremely competitive world, especially with React, Next, Solid, Vue, Nuxt and Angular. Adding any hurdles to a newcomer at the very beginning is bad news. The first step that you want for trying to onboard someone is not confusion. Third, this is very optimistic thinking. Many people are just going to give up and move on. This is firing the footgun right at the start. In my experience onboarding people, they're going to put the components in lib/components. This footgun everyone talks about with _Component.svelte being exposed as public seems imaginary. And if it does exist, seems to be a poor justification for ruining a clear concise file name with an objectively ugly +.
But why though? Why can't a normal file name be the direct role in the functionality of the route and the _ character means the router doesn't care about it? Shouldn't public and working be the default? Is this really worth all the pain & confusion ? And what problem is this solving exactly? People might expose a component? What other framework in history has ever made routes private by default?
The reality though is that with File System routing, you have directory based too. So it's not like the routing changed, it's more that the flexibility and freedom of file system based routing was taken away. You could always make a folder and throw your route inside before. But now you are forced to do this. The File System based routing is more intuitive to me because that's how I organized stuff on my own person computer. I don't make a folder to put a single file in it. I make everything as concise and pithy as possible. I love pithy filenames. Sacrificing usability, flexibility and readability for Maintainability is not a good trade off. (Especially since I don't maintain SK. Ha!) I have all this redundant naming now and folders with a single folder in it. Instead of shop/product/[id].svelte, it is now shop/product/[id]/+page.svelte. An extra folder for what gain? That is losing order and organization in my folder structure. I could make it shop/[id]/+page.svelte but I also have shop/cart/[id]/+page.svelte too ! If something doesn't need to be a folder because it only contains one item, then it shouldn't be a folder. A folder is conceptually for containing many items. It's best to have your folder structure as shallow as possible so you're not constantly diving unnecessarily deeper. That is order. Otherwise, everything becomes bloated, hard to find and difficult to manage. Instead of api/cookies.ts & api/darkmode.ts, I have api/cookies/+server.ts & api/darkmode/+server.ts. This adds a completely unnecessary directory! Having a folder of api/ with all my routes there makes perfect sense and is the most rational way to organize it. And how its always been done and "if it ain't broke, don't fix it!" This supposed benefit of making routing level by folders is dubious when I'm forced to make my folders unnecessarily deep. And did anyone really care about that before anyways? So what if you have todos/ and about.svelte? If you care that much, you still had the freedom to make it todos/ and about/. But now you're forcing me to do it as well! This has caused my entire project to be so bloated now. Don't be fooled. The amount of complexity in the system is the same, it's just been shifted. Yes, I can do CMD + P in VS Studio. But I should also be able to find my files in the directory easily ! I had that before and now it's lost. Using a specific feature of a tool as a crutch is bad. It's a sign of disorder. I can cruise through my directories much faster than CMD + P so again, wasted time for me. And I get that some people use CMD + P. But not being accommodating of people's development styles is a sign that the DX is no longer a priority. . Easiness is being traded for "Simplicity".
This is true, but I also had a lot of files with actual names like profile.svelte and help.svelte so the burden was most less.
No. But what is the reality? We all have too many Chrome tabs and VS studio tabs open. It's the nature of the beast. However, we shouldn't do things that exacerbate it. And shifting blame here to the developer instead of acknowledging that this slows down work, and reduces DX is suspect. It's a red flag to me when I'm being told how to develop.
The truth though, this isn't really innovation. It's pretty similar to how you would organize a Java project. What innovation is happening here? The directory based routing already existed. The file routing option was just taken away. The + isn't an innovation. It's just switching from routes working by default to routes being broken and private by default. So now instead of putting _ on private components that are colocated in routes/. We're putting an ugly + on every single file that is public. I'm not a big fan of having files that say only Svelte was innovation. Making a project more ridged isn't innovation. It's just sacrificing the beautiful development experience and flexible filesystem-based routing that the SK home page claims. Flexibility & functionality was just taken away in the name of "simplicity". Where did this notion that two ways to do something is a sin? Since when is two ways to do something confusing? A million ways to write this sentence. Perhaps if the file and folder routes contracted, but it was pretty clear. Is simple a greater value than DX? To be clear, my only issues are the naming convention, private by default aka the + and removal of file based routing. Which at the end of the day is pretty petty. But... It felt like before that productivity aka easiness (the DX) was the supreme value. Now it seems it has shifted to the philosophy of Rich Hickey. A man who hates ORM. Even though ORM are easy & save massive amounts of time. A man who created Clojure, which is a dialect of the Lisp programming language on the Java platform. If that gives you any hints. The man is far more brilliant than I will ever be. But in 2022, I'm using server-less Firebase with SK for maximal productivity and ease. Minimal code. Maximal results. Easy Made Simple. |
Beta Was this translation helpful? Give feedback.
-
I really like this major rewrite since I have previously had a very hard time understanding how things fitted together, where things ran etc. even after reading the docs again and again. Things did fell into place with this rewrite. However One more thing: I agree with the point raised earlier that this change favours pages but not api:s. Having an api folder with a bunch of folders with single files feels clunky. Is there a solution for this on the horizon? Otherwise it feels like it may become one reason for why someone might choose something else for a “api-heavy” project. Also, regarding co-locating components. If that was something I would do, then I wouldn’t mind putting it in a subdirectory, I.e I could have lived with a solution like
Why would you like to intermingle route files with a bunch of components anyway? If you want collocation, why not just put them in a (hidden from router) subdirectory? Was this considered? Then simply the price to be paid for someone who wants to collocate components would be to “put them in a subdirectory”, instead of forcing everyone else to add a plus sign to all their route files. Maybe there is a simple answer why this is a bad idea, but I haven’t seen it considered. To summarize: I like the changes overall, I am a bit worried that something that should be a small detail ( |
Beta Was this translation helpful? Give feedback.
-
@nikfp I agree, while it's definitely different I think these changes are a huge improvement and fix a lot of the things I felt weird about with the old SvelteKit. |
Beta Was this translation helpful? Give feedback.
-
I have been feeling conflicted about editor ergonomics of folder-based routing with the What bugs me is that it is annoying/harder to visualize my files. When I use the file explorer in my editor sidebar, I need squint my eyes to find the folder, and then find the file that matches the correct indentation. In the tab menu, all the +page filenames are not optimally expressive/differentiable and is slightly difficult to sift through. Also, when only one tab is open I cannot tell which file I am looking at (depending on the When it comes to selecting a file, I know I can use the Ideally, files would have filenames that describe what they are, like As a thought, config-based routing is not bad since it is solid, familiar, and has not too many points of differing opinion. Using a router-file makes slightly more sense in git version control. And you can have files like There is no perfect solution and this is a minor nitpick. I am happy with the current because it works. I trust the judgement of Mr Svelte for design decisions. |
Beta Was this translation helpful? Give feedback.
-
My biggest problem with this whole change is how some of these things are being communicated and argued for. This is not directed only at you but most of the "new routes are better camp".
The directory is called I can understand the argument for saying The argument I dislike here is talking about "Oh if you want to have a widget or whatever If the
I agree that the new way is more structured. The downside is that you can end up with a lot of directories, where each of them have a single file in it. For example with all of my Again, I think enforcing directories is what is needed to bring all the TS convenience and that is a tradeoff I'm in favor of. I disagree it is objectively better and I think people are being too dismissive of people who voice their pains with editors that they did not have prior to this change. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I've seen a lot of negative feedback on this repo about the updated routing. I know that within the community this has been a huge point of controversy, and the core team did a great job of explaining the technical reasons for making the change, which were sound. I thought it would be useful to post a few reasons why this was a good change from less of a technical, inner workings perspective, and also encourage others to share their opinions. All of my points are in response to opinions of others throughout the community.
TL:DR
People don't like the
+
character at the beginning of files.I've seen reasons for this ranging from "I don't understand" to "It fits no current convention out there" to "I just hate it and it's ugly".
Let's think about this for a moment. To start with,
index.**
is a current convention for JS based projects to access the entry point of something - package, application, website, etc. But at one point, this wasn't a convention. It could have just as easily beenentry.**
(which semantically might have made more sense) orstart.**
. I can see where the friction comes from that SK is moving away from the broader convention, but it's to the benefit of the framework as a whole. Every innovation ever didn't make sense until someone did it and the benefit became apparent, and then it made sense. So if we giveindex.svelte
some further consideration, it stands as the entry point, but to what exactly? In the context of SK you had to read the docs, know that the filename was reserved and for what purpose, and then you could effectively use it, because unless you had one page, you probably had many more than oneindex.svelte
lurking. This left a possibility of some confusion to the developer new to SK, because you could clone a repo, open it up, and make an assumption on whatindex
was and how it would behave. This in turn could lead to some bad (or even dangerous) practices.Then we had the other "special" files -
__layout.svelte
,_db.ts
, etc. Everyone thought this was great, but to me it always felt a bit disjointed. Nothing was consistent, there were reserved filenames, you had aload
function in a separate script block in a file that pulled information from a siblingendpoint
file, an underscore meant the file wasn't considered a route but two underscores followed by one of a handful of special names meant that it could represent a route - or a layout - or a reset - or an error page. I found myself in the docs all the time until I was able to grok all of that through sheer memorization. I'm sure others had the same experience.The contrast to this is the new
+
character and directory based routing. From the perspective of someone who has never been in a SK project and clones a repo, the first thing that comes to mind is "this means something, and I need to know what". You are prompted to read the docs or ask someone who knows, and to learn it. This is good because it removes most of the opportunity for ambiguity and confusion by forcing the developer to learn what they are looking at. Every framework has it's quirks, including NextJS, Nuxt, and Angular. This puts up some guardrails and encourages you to understand the SK quirks before you fire the foot gun.THEN it actually gets much simpler, because reasoning about the file system for routes follows a concise set of heuristics:
+
character indicates that the file has a direct role in the functionality of the route. No+
character and the router doesn't care about it. Add co-located support files as needed. (but you probably won't - everything can be done in the+
files or should probably move into$lib
anyway)page
in the name pertains to the page at this level of the directory structurelayout
in the name pertains to this level and any descendants.svelte
on the end pertains to rendering and related logic.ts
(or.js
) on the end has to do with data and not renderingserver
in the name only runs server side.That's it. Now there is logical separation of what file does what task.
.svelte
files get cleaned up as load blocks move out, things get abstracted away, and the overall experience is cleaner. I read through the new docs ONCE and this made sense, and I haven't had to look again. People say the new way is less intuitive, I disagree.Back to
index
vspage
. You are working to render a page, correct? Using thepage
naming conventions is about as semantically accurate as you can get.People don't like the directory based routing vs the File System based routing
Why though? Directory based routing sorts better, making it easier to find things. It's clearer what does what - a directory is a route, the files in the directory define behavior. It's still file system based routing, but it's actually simpler if you look at it.
As an example, here are two file paths on the old file structure:
Those two files output exactly the same route. So which do you use and when?
Here's the new way:
That's it. You do it that way. No ambiguity.
Here's another example:
How does this sort? Just like I listed it. The problem is when a human is looking through this,
orders
should go beforeproject
, but it doesn't. Similarly,customer
should be listed above bothorders
andproject
, but it's in the middle. This is default sorting behavior as seen in your editor sidebar or if you list files and directories in the terminal. Great for computers, bad for mere mortals.You can update to the new way, and it all sorts in the proper order:
I know which one I'd rather be pawing through.
Searching for files is now too hard --- too many
+page.svelte
I acknowledge that there are now more
+page.svelte
files in each project. That's the nature of the update. That said, I have two points on this.First, you should try searching by directory instead of by file. It's actually easier to get right to what you want by doing so. For example, take this file structure again:
Hitting
ctrl+p
in vscode and then searching forproject page sv
gets you one result:routes/project/+page.svelte
. Even if that same directory had a+page.ts
, and a+page.server.ts
in it, you would still get one result. Swap toproject page server
and you get the server file, and that's it. Use the fuzzy search and save yourself some headaches.customer
gets you into that directory,orders
gets you into that directory, etc., then add something unique about the file you are chasing.Second point, this isn't really very different than it was before. I'd bet your project had a heck of a lot of
index.svelte
files strewn about. So you would have still gotten a lot of results searching for index anyway. To get something useful back you would have entered another character string to narrow it down. I recall using the fuzzy search before the same way I do now. I don't find myself using any more keystrokes, and since things have clearer separation of concerns I can actually better target the file I'm looking for.I now have a hundred
+page.svelte
files open at once.Yes, but should you? I can't think of a good reason I'd be working on more than one or two files at one time. Someone may post a valid reason otherwise, but why not close the rest? Problem solved. I get anxiety when my text editor has too many tabs open. One task at a time.
If you still need some clarity on where you are, your editor probably has a breadcrumbs feature. Turn it on. Never lost again.
One last thought in closing:
It's important to remember that innovation can't happen without change. We all want things to get better, but there is a stability sacrifice we have to make in order to do that. It's more so on a framework that is still in beta, which practically guarantees breaking changes, AND it's a JS framework, meaning things are going to move really fast anyway.
Another way to look at this is the old quote:
"The definition of insanity is doing the same thing over and over again and expecting a different result"
Feedback from others is welcome and appreciated.
Beta Was this translation helpful? Give feedback.
All reactions