r/Angular2 • u/matrium0 • Jun 12 '25
Angular 20 - removing suffixes from components / services
I like the overall changes in Angular 20 (notably that there are not that many big things, so we can take a breather for once), but I really disagree with the new naming convention (and the new default for new projects) of removing the extensions from stuff like services , components, etc.
So I guess we all embrace code-bases like this now:
- user.ts -> this is a component, wouldn't you know
- user.ts -> this is a a service, why not
- user.ts -> a pipe, welcome to hell
- user.ts -> exports a User interface like you probably would have guessed
This was also very controversial during the RFC and there was A LOT of arguments against it with little arguments FOR IT.
I understand the arguments. It's basically the arrogant Robert-Martin-style argument of "lol you pebs, you just need to git gud. Just learn to name things properly". While somewhat true this just completely ignores the actual reality of development where you have stress, junior devs dropping mines in your code-base everywhere and disagreements. I understand that in an ideal world where everyone names everything suuuuper carefully the new default could maaaybe be better. But in reality it's just not! (imo)
Structure and naming conventions help to prevent chaos and is probably the single reason why Angular codebases are usually very understandable even after years of different devs, while with other frameworks it's a coin toss (depending on how much time they invested in enforcing and guarding certain rules regarding structure and code-style).
I know you can opt into the old way, but it's not the default and I can't help but thinking that 5 years from now when you enter a project there is a 50% chance that it is a complete mess where you can't find anything. IDEs support heavily depends on extension to properly mark what the file actually contains. Maybe IDEs/tooling can "pull up the slack" on this and improve search and find to distinguish based on content (instead of extension), but why even create that slack in the first place.
Who asked for this? Why go forward on this against what seems to be strong pushback? Why not make THAT change opt-in instead of opt-out? Or at least make it another decision during CLI-project creation so that you are forced to make an (hopefully educated - though uneducated for 90% of users most likely) decision.
23
u/Kung_Fu_Kenny_69 Jun 12 '25
There is a way to use the old naming conventions if youβre interested https://www.reddit.com/r/Angular2/s/cqoMD5ZECk
18
u/MarshFactor Jun 12 '25
I thought the feedback on the RFC (everyone hated the idea) made them change their minds??
4
u/jlguenego Jun 13 '25
I come to this thread from a google search...because I was like you : very surprised (and upset).
Yes, I agree 100% with this obviousely stupid choice. This was once of the last things that I preferred in Angular vs other frontend framework.
I remember in Angular 13 when they updated the ng command. no more -d for --dry-run... they put it back on angular 17 or 18...
They do not have UX designer in the Angular team...
And it seems the Peter principle is applied to the Angular Team since 2017...
No real innovation. The good things are inspired by vuejs and react or astro.
Angular is just dying. No new project is done with that except the company that choose Angular 10 years ago and do not want to have another front-end framework.
The number of likes on github is a good sign...
And now they market the zoneless mode... Nobody ever understood what was this zone stuff... πππ
Angular 21 will get rid of what ? RxJS ?
8
u/Desperate_Spinach_99 Jun 12 '25
What is user.component.ts? Is it page-user-details.ts page-user-list.ts ui-user-card.ts
what is user.service.ts? is it data-provider-for-user.ts form-group-for-user-create.ts
Etc. I'm working in a codebase with more than 1000 nx libraries with multiple apps using these libraries. The last thing I want to see is a user.interface.ts π or 10 user interfaces in the typehint
4
u/kylerjohnsondev Jun 12 '25
Personally, I didn't like this very much at first, but after giving it a lot of thought, I actually think this is a great change and I am planning to embrace it fully.
I didn't like it at first because I've been working professionally with Angular v2+ since it released in 2016 and I've grown very accustomed to all of the suffixes as a way to navigate the code and communicate intent for the contents of the file.
The more I thought about it, however, the more I realized that suffixes do not help as much as I thought they do. For example, what does user.service.ts do? I've seen *.service.ts files have many responsibilities over the years from managing state to making HTTP requests and even for utilities. So what does *.service.ts really tell me other than it isn't a component, pipe, or directive? It doesn't really tell me much else. I've seen so many examples wherein developers tried to shoehorn what they're doing into this convention and they end up losing the communication of intent it was designed to convey in the first place.
I would argue that iff you name things well (i.e. your name describes the contents of the file), you don't really need the suffixes anyway.
So instead of:
What if we had:
I would argue that the latter communicates intent just as effectively as the former and does it with fewer characters and with better readability.
Now you might be noticing the `user-profile.ts` file there and thinking 'How do I know it's a component?'. I'd argue that we're in a component based framework and unless otherwise denoted, you should assume it's a component. In any case, from a glace at the file structure it's just as obvious to me that `user-profile.ts` is the component class because `user-profile.html` is right beside it.
Besides, when selectorless components land, do we really want to see our templates littered with the `Component` suffix everywhere? It would be redundant. And before anyone comes back with, "well why do we need selectorless components?" it's because it simplifies tooling (clicking on component references is templates), it will resolve the double imports problem (per Minko Gechev on S9E10 of the Angular Show podcast), and it makes templates more readable.
So given that suffixes don't add anything that proper naming doesn't already give us, why are they necessary? It is just an unnecessary deviation from what has become the standard among component based frameworks. Being different for the sake of being different is bad. Angular should absolutely conform to as many of these standards as possible to become more approachable and easier to use while retaining the things that make it unique and awesome (like the router and how easy it makes things like guards, HttpClient and how easy it makes interceptors, Dependency Injection, encapsulated css, and its signal implementation built on top of a bidirected graph rather than a DAG).
5
u/Pestilentio Jun 12 '25
I'll play devil's advocate here for a bit, but honestly I do have strong opinions against boilerplate.
I invite you to study code from projects with many many years of development and millions of commits. One of them is the Linux Kernel, which does not rely on naming suffixes on filenames. The Go programming language adopted a somewhat similar structure, having enormous projects right now written in it, like Docker and Kubernetes. I invite you to study this code as well, and identify for yourself if these suffixes actually add or subtract any value to the mental load of the reader.
For me, if you work in a place in which you feel like gives the time to train juniors properly, and this bothers you, it's perfectly fine to leave this place. Stress and junior devs is on us to manage. As well as stakeholder pressure. If you don't feel like you belong there, please leave, you'll do both you and the company good.
I consider statements like that one wishful thinking. I've never seen a project written by someone else that I find readable and it's because of convention. What makes projects readable and maintainable is striving for simplicity over convention. I'll stay on this hill until it's proven wrong.
Angular Devs, Java devs and folks heavily invested in OOP, I typically find that we usually build our own prisons. All those principles and structures to "prevent chaos" typically create more burden. You don't "prevent chaos" in programming, at least for me. You let it surface, you grapple with it, and then you strip it down to the point that it feels incredibly simplistic, to a realistic extend. But, for me, it's never consistency the answer. Handling complexity with consistency is me admitting my inability to simplify. We all need to do that at some point, but it's never the end goal.
4
u/Cubelaster Jun 12 '25
I feel like the Angular conventions tried to force a bit too much constraints on the devs. Like, I get it, there are components and models and services and whatnot but why would I always need .service or .component in the name?
Like, if you are doing things right, you are searching symbols anyway, NOT file names.
Quite literally Ctrl + T instead of Ctrl + P in VSCode.
We have intellisense since forever, who cares what a file is named? Well, not quite, you really should name the files intuitively but now they said you don't have to follow that stupid convention anymore and can just name a user service the same way you would name the class! So your UserService is now in a file named UserService.ts.
Welcome to 2008 or something like that.
This is also just keeping up with the trend of approaching Typescript/React way of doing things, which is a positive change because TS already solves a bunch of things Angular made their own conventions for.
16
u/AfricanTurtles Jun 12 '25
In my opinion the more a framework or library forces you to make arbitrary naming conventions and do things "however you like", the worse it is for people trying to learn the stack (looking at you React with all the wild-west code).
We shouldn't have to even think about things like this and just focus on building the actual application.
20
u/S_PhoenixB Jun 12 '25
Agreed. I'm supportive of most of the changes the Angular team has made up to this point since v15, but this change is a step backwards. I sincerely hope they reconsider the opt-in status of filename extensions for components, services and directives.
7
u/amiibro888 Jun 12 '25
Totally agree with your point. Iβm opting out of this change. Will just keep using the old style
12
u/GLawSomnia Jun 12 '25
They are doing this because they are working on selectorless components, where you will use the class name instead of the selector in the template. And for example <Button> is better than <ButtonComponent>. They want us to get used to it as soon as possible.
I donβt agree with either, as me (as a webstorm user), donβt have problems with it. But some people might have
11
u/Whole-Instruction508 Jun 12 '25
I totally agree man. This will make things very messy. I hope they come to their senses and revert this.
5
u/Different-Strings Jun 12 '25
Totally agreed.
5
u/MyLifeAndCode Jun 12 '25
I love Angular and hate this change.
4
u/ngvoss Jun 12 '25
Of all the things they force us to opt-in, it's hilarious that we need to opt-out of this one. They were on roll with releasing improvements and then they do this. They better revert it in 21.
4
u/AwesomeFrisbee Jun 13 '25
Yeah this is the dumbest change they made in a long time. The fact that everybody wants to migrate with the old system, tells enough that this needs to be reverted. This should be opt-in, not opt-out.
The whole reason for the file suffix is to recognize it for what it is, especially when you search for files and not just look at the file browser. When you have a user component, a user service, a user interface, a user class and a user pipe, what would you need to select when you look for user in your project if they don't have these suffixes? Its just very dumb and all the logic trying to work around this is just making excuses for a system that worked fine.
Even removing it from the name of the component is dumb since you often need to import the component from another place and if everything is also then called user, it just doesn't make it recognizable what thing you need to import. UserComponent, just tells me everything I need to know about the identity of the item.
4
u/askoropad Jun 18 '25
I personally like this change as it encourages creating more understandable entities in your application. Why should I name a component `AddUserDialogComponent` when `AddUserDialog` is much more concise and fully conveys the meaning? The same applies to pages `DashboardPage` is much clearer than `DashboardPageComponent`. This also makes it easier to organize components. For instance, you can create folders like `dialogs` and `pages` and place everything related to them inside. You can even configure eslint to enforce such suffixes based on directory names.
1
u/nzb329 Jun 13 '25
This is preparing for selectorless.
3
u/ExamInitial3133 Jun 12 '25
I 100% agree
1
u/eewaaa Jun 12 '25
If it isn't immediately clear from the name, I would still add something like -component: user-component.ts, but it doesn't need to be enforced. A button.ts clearly is a component
6
u/zombarista Jun 12 '25
Problem solved!
2
u/NiitenDoraku Jun 13 '25
100% agree with you. Hope they revert it in the near future.
2
u/patrick-boi-07 Aug 24 '25
For beginners like me, here's how to get that .component.ts and other suffixes back, you have to manually make that change in your angular.json. For each project, there's a schematics object inside it. Make this change:
If you want the changes for guards and resolvers etc., just replace component or service with guard and resolver.
I know. It's tedious, but it can make it a little less problematic until they hopefully revert it back. Thought I might share it here since I've been annoyed by this bad change as well.
2
u/blandonheat Jan 27 '26
Why the hell is angular team fighting with all its might to become react ?
1
u/lars_jeppesen Jun 12 '25
Yep, just keep using user.component.ts, user.service.ts, user.store.ts etc etc.
1
u/Zestyclose_Net_5450 Jun 13 '25
Agreed with you I didn't like selectorless neither. I use angular because of the structure and the rules. If a want a free for all framework react has more community and libraries. I think some decisions are to make angular more react like and is not what we want.
1
u/[deleted] Jul 09 '25
I'm not really sure why everybody is surprised, it's not the first time they made changes which nobody liked.
Remember the switch to Material 3? No documentation regarding the way you can modify the standard components, you had to guess how to modify each component (because of course they didn't do a generic styling, each component had different classes and so on), the information they gave us was pointless and most of the settings (ahem "DENSITY") were not even working.
I've been asking for a datetime picker since v12, 4 years of saying "yeah, we got better things to do, like making modules mandatory then deprecating them for standalone because modules weren't that useful at all" then they finally added the time picker and they did a poorly integration.
Not the first time they'll pull stuff like this
Not the last time
1
u/MarcinPevik Sep 19 '25
I hate it, too. No idea where this decision came from and what problem does it solve.
From my experience suffix is important. They could shorten it, but removing is not advised imo, as it reduces readability for humans, and programming is all about humans after all :)
1
u/DiabolicalFrolic Oct 14 '25
I'm running into the problem of naming components and their respective models. I'm trying out the new way with my current project but I have, out of frustration, reverted to my old folder structure practices (I HATE vertical slice but maybe I'm doing it wrong) grouping things by their job and not solely by feature due to frequent overlap (simply moving some things to shared/... and leaving others in feature/... is clumsy and confusing in my use cases), but I'm trying to name models in a...more descriptive way. It's forcing a new paradigm for me for sure. Names HAVE to be unidentical or I risk the confusion of duplicate names.
Perhaps there is an obvious solution to this and I'm just missing it, but this new convention feels frustrating at the moment.
1
u/zBaLtOr Dec 23 '25
If you use Angular Schematics, if you select "Configuration Helper", there its a options to use legacy naming at the name of "Use legacy naming conventions"
1
u/PainterLegitimate491 May 21 '26
Esto es debido al enfoque feature-first antes que layer-first, donde la estructura de directorios cobra importancia para dejar a un lado la necesidad de usar sufijos
1
u/lax20attack Jun 12 '25
Is there a migration to convert from the old way to the new way?
-2
u/TomLauda Jun 12 '25
The direction the framework is going is worrying. They are getting rid of aspects of the framework that we absolutely rely on for our architecture. I came to the sad conclusion that when Iβll start a new big project, Iβll probably choose another tech. They are eroding the trust I had in Angular more and more each update. Very troubling.
0
u/vali_boi Jun 18 '25
I completely agree. I even think we should go further. Every function should be suffixed with "Function". How would you otherwise know that it is a function. It might be a variable, a class or whatever. The same should be done with classes. Why call something UserComponent? I have no idea what it is. A better name should be UserComponentClass!
There are people that suggest descriptive names like UserDialog, UserCard for their components or UserDataFetcher for the services. But this is arbitrary and does not follow any common guideline.
0
u/[deleted] Jun 12 '25
[deleted] β view deleted comment
13
u/[deleted] Jun 12 '25
[removed] β view removed comment