RocketChat / feature-requests

This repository is used to track Rocket.Chat feature requests and discussions. Click here to open a new feature request.
21 stars 9 forks source link

Port Rocket.Chat to Typescript #166

Open novacrazy opened 5 years ago

novacrazy commented 5 years ago

I mean this in the kindest way possible, but this thing is a mess.

Like half of the commits in the last month have been reverting accidental regressions for one reason or another. It's impossible to track what any value is at any given time, and I still get random type errors and undefined values in my logs every few days.

Bug fixes and features both are being limited and slowed down by not having any idea what's going on for a piece of code. This project is frankly unmaintainable, and I can plainly see it's taking a toll on the members here.

A solution to this that isn't too extreme would be to simply start porting things to Typescript.

Strong static typing without changing much of the actual code would drastically improve the safety of the application, everywhere, and probably fix 1600 bug reports here in the process.

My organization has been using Rocket.Chat for about six months now, and I've tried to keep up with the progress made, but every single commit/PR I see that "fixes" issues caused by sloppy duck typing kills me inside. If you had known the type from the start, it wouldn't have been an issue.

Not only that, but I can't even contribute and fix things, because I don't have months to grok the entire project and learn what the types actually are. I have no idea where half the data structures here are declared or what they contain, making it impossible to do some of the things I want to do. If they had static typing, more people could understand things and craft better solutions.

This is not an easy undertaking, but it's far from the hardest, and would save countless man-hours in the future, assuming you want this project to continue for a few more years. Otherwise, we may as well switch to something else now.

geekgonecrazy commented 5 years ago

First off thanks for the feedback.

This is perhaps not the best place for a discussion format. I think we have a feature request open for this and it has definitely been discussed before.

I'll try and address a couple of things real quick:

I'm guessing if paying this much attention to commits you've also seen that recently there has been a lot of work to clean our code base up. If not there has been :)

Things like: Removing some meteor dependencies, forcing removal of all globals and instead using imports, forcing more strict eslint rules, etc, etc. All of these are changes to improve the code and open up options such as maybe porting to typescript. But also making it easier to open up a code editor and use intelli-sense type features to make your way around the code.

All of the typescript related arguments i'll leave alone. If you've seen Rocket.Chat apps you'll know that we have nothing against typescript and know its usefulness :)


I'm going to move this to feature requests since thats what this is.

ggazzo commented 5 years ago

hey @novacrazy, thanks for your feedback, do you have any comment about Flow instead of Typescript? I'm not saying we gonna use x or x, but its a option as you suggest use only to Type objects do help the developers, and I think Typescript its a little bit intimidating for new developers, and we have lot of different levels of developers...

novacrazy commented 5 years ago

Well, I'll be honest, it does seem like Flow has had quite a bit of development since I last looked into it four years ago. However, I still feel Typescript as a language is quite a bit more powerful, by actually being a full real programming language. Flow is simply annotations to existing Javascript. Typescript has great cross-platform IDE support, as well, which is a large plus. Here is a decent modern comparison

Typescript is quite strict at times, which can be frustrating to some new people, but on the other hand I find totally untyped regular Javascript to be depressingly hard to work with on projects like this, even after many months of trying to patch things. Perhaps Visual Studio handles it better than others, with Intellisense as previously mentioned, but I and many others don't use Visual Studio.

I've seen some talk about moving the web frontend to React eventually as well, and Typescript works flawlessly with JSX, so that's something else to consider.

Keep in mind that I don't intend to insult any of you by saying it's a mess. It's certainly better than the original Coffeescript version... but I simply can't work with this project as it stands now, without having full knowledge of all the systems. I want to see it better, faster, easier, and static typing is a feasible way to do that.

ggazzo commented 5 years ago

thanks @novacrazy, actually I know the differences between both, but as you started pointing types as a solution to N problems I suggested Flow.

To be very honest, I have seen more than wrong returns here and I don't think typescript will cover 30% of them. Sometimes an IDE support helps a lot for sure but I don't believe that rewrite will be so magic, we made very bad decisions about how to code some modules and that problems are perfectly reproducible in Typescript, thats why I don't like "Typescript will save the world".

(my personal opinion here and maybe tomorrow the company/community can decide something different) but its very complicated, change all the code base to a different language, as you had some troubles to understand the project, maybe we can loose some contributors because they are not able to understand even the language.

I'm not against Typescript and Rocket.chat.apps are build using Typescript, I just want more discussion about.

ggazzo commented 5 years ago

ps: I'm not saying that our code it's easy/good to understand or maintain. 😶

novacrazy commented 5 years ago

You're right. The important part is the strict/strong type checking, so Flow is definitely a valid option. My intent wasn't to fall into that "Typescript will save the world" kind of thinking.

However, Typescript is stable and known to scale well with complex applications, and provides more extensive compilation options. For example, I'm still holding out a bit of hope that Rocket can move to React eventually, so having strongly typed JSX code (TSX) is definitely an advantage. It also supports modules by default, supports ES6+ features that can compile down to regular ES5 code, and has good support for third-party libraries using declaration files -- many of which are already out there provided by the community.

It's about as good as it currently gets for ever hoping to add stronger language features to JavaScript without switching to a totally different language and runtime entirely.

WSLUser commented 5 years ago

I agree to use Typescript over flow, especially from a support perspective. People can hate but Microsoft has been extremely supportive of it's OSS projects, including TypeScript. If this wasn't the case, then I'd question why so many of their OSS projects are so popular (hint: VSCode, PS Core, and Typescript come to mind).