Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate event shorthand methods #3214

Closed
gibson042 opened this issue Jul 4, 2016 · 39 comments
Closed

Deprecate event shorthand methods #3214

gibson042 opened this issue Jul 4, 2016 · 39 comments
Assignees
Milestone

Comments

@gibson042
Copy link
Member

@gibson042 gibson042 commented Jul 4, 2016

As discussed in the core meeting, we should deprecate on/trigger event shorthand methods in a pre-4.0 minor release.

EDIT by @mgol: I fixed the meeting link, it used to point to the latest day on IRC.

@john2014
Copy link

@john2014 john2014 commented Jul 4, 2016

Please DO NOT do this. A huge amount of code, especially in top 1 million websites, relies on a LOT of these event shorthands. The reason .load() was deprecated was because it was ambiguous. Not only these remaining shorthand have no ambiguity but is actually much cleaner code. Do not fix something that is not broken.

A good example: We would have to change $("#div1").focus() to $("#div1").trigger("focus");
$("#div1").focus(function(){ DoSomething() }) to $("#div1").on(""focus",function(){ DoSomething() }));

Please do not break such important shorthands just because one person complained about it. The biggest reason to continue to use any library is its backward compatibility. If it keeps breaking stuff for ZERO apparent gain, then many users will either seriously consider moving to different library or stay with older version. I am guessing jquery does not want that.

In addition, there are millions of jquery plugins which uses these shorthand and there is no way every single one of them would be updated. This would break the entire jquery ecosystem.

I hope you guys see the magnitude of this change. Not only do users not gain from this; but it will break lots of stuff for no reason.

@scottgonzalez
Copy link
Member

@scottgonzalez scottgonzalez commented Jul 5, 2016

I'm +1 on deprecating, -1 on ever removing from the default build. It's already easy to exclude in a custom build, but the deprecation is a good signal to developers that they should aim to not use them.

@timmywil
Copy link
Member

@timmywil timmywil commented Jul 5, 2016

I'm not a fan of deprecating something we don't plan on removing. Considering that, I might be a -1 on deprecating these. They're just too prevalent to remove, and I don't see the downside of using them if you like them. I prefer .on too, but I have no disadvantages in mind to back up a harangue for using an alias.

@scottgonzalez
Copy link
Member

@scottgonzalez scottgonzalez commented Jul 5, 2016

The reason I'm in favor of deprecating, but not removing is that it will encourage plugin developers to support users who want to exclude the event alias module. This is the only module, besides the deprecated module, that we support excluding with jQuery UI.

I've also personally disliked these methods for many years because they operate in the reverse order of what's expected for the trigger scenario (the primary action is firing an event, not taking an action like the native equivalents). The result is close enough to the expected, native behavior that most developers don't notice, but it's definitely been a source of pain for a long time.

@dmethvin
Copy link
Member

@dmethvin dmethvin commented Jul 5, 2016

The Bootstrap team has a similar thought to @scottgonzalez in twbs/bootstrap#20203 and are planning to use the slim build. Obviously most consumers of Bootstrap will be using the full build but it's nice for end-developers that a plugin doesn't unnecessarily force them to use a full build.

I'm fine with deprecating but not ever removing. Slightly more complicated, we can not deprecate it and come up with another term and use that in the API docs to define APIs that plugins should avoid. It's already possible to exclude event-alias in a custom build, but without some signal to plugin writers about what to avoid that isn't going to help much.

To @john2014's concern, even if we removed event aliases in the core library we have always provided plenty of compatibility helpers to make the transition easier. If someone is moving from jQuery 3 to a hypothetical jQuery 4 without event aliases, they would just add jQuery Migrate 4 at the time they changed to jQuery 4 and it would report the things to fix.

@mgol
Copy link
Member

@mgol mgol commented Jul 5, 2016

To add to the above points, deprecating these shorthands will mean the slim
build won't contain them which, in turn, may serve as an incentive to
plugin authors to stop relying on them and at the same time will not block
people from upgrading to a newer jQuery since the full build will continue
to work.

Michał Gołębiowski

@dmethvin
Copy link
Member

@dmethvin dmethvin commented Jul 5, 2016

It's also interesting that Bootstrap actively disables aliases in their unit tests so they won't accidentally be used. They could have used a custom build of course but this way their tests generate a clear error message if one is used accidentally.

@BillJones50
Copy link

@BillJones50 BillJones50 commented Jul 5, 2016

I agree with @john2014 that the tradefoff is not worth it (saving few lines of code vs breaking a lot of user code + lots of jquery plugins - maintained or unmaintained; but actively used).

@john2014's concern, even if we removed event aliases in the core library we have always provided plenty of compatibility helpers to make the transition easier. If someone is moving from jQuery 3 to a hypothetical jQuery 4 without event aliases, they would just add jQuery Migrate 4 at the time they changed to jQuery 4 and it would report the things to fix.

The most important point is backward compatibility. Users should not have to keep modifying their code (and every jquery plugins they used), everytime a new jquery major version is released.

Note: Jquery migrate will certainly solve that "newly created" problem. But that will involve users having to add two javascript sources instead of one. Many users may not even be aware that Jquery migrate exists. I dont think saving few lines of code is worth breaking lots of code.

As you may know, Jquery is already less than 34 KB when you load it from Google CDN and its permanently cached. Reducing files size to 33 KB (or even 29 KB) isnt going to make much difference. A single image on Facebook is more than 60 KB. So filesize should not be an important criteria. IMHO, the most important criteria should be backwards compatibility and adding new features to continue to make Jquery a great library.

@timmywil
Copy link
Member

@timmywil timmywil commented Jul 5, 2016

@BillJones50 @john2014 I think the whole core team agrees that these should not be removed. Some would like to warn against their use, though, and deprecation might be the best way to do that.

However, I still think the word "deprecation" will give the wrong signal. That is, some people will believe jQuery intends to remove them down the line (as is evidenced by @BillJones50's comment), and we don't.

@BillJones50
Copy link

@BillJones50 BillJones50 commented Jul 5, 2016

Thank you @timmywil

I forgot to add that using shorthand not only saves significant coding time, but also reduces end user filesize (since there is less code). Using shorthand is a win-win for developers.

@scottgonzalez
Copy link
Member

@scottgonzalez scottgonzalez commented Jul 5, 2016

I forgot to add that using shorthand not only saves significant coding time, but also reduces end user filesize (since there is less code). Using shorthand is a win-win for developers.

Both are a lie.

You don't save significant coding time with any shorthands like this. The time it takes to type a few characters is negligible, even over an entire year's worth of coding. Even the time you spend typing in general while coding is fairly small. Keystrokes are not where you get significant gains in development time.

As for end user file size, I assume you're referring to the number of bytes transferred, not the number of bytes in the cached file on the user's drive. The number of bytes you think you're saving during transfer (bandwidth) disappears when the code runs through gzip prior to the transfer.

@BillJones50
Copy link

@BillJones50 BillJones50 commented Jul 5, 2016

You do realize that not everyone uses Gzip on their server.

In addition gzipping (compression) increases server loads (it has to compress every single time unique visitor requests javascript files) and is not suitable for all situations. If we can compress codes (using shorthands) before the gzip process, its lot more useful.

I am not sure why you think providing quick shorthand is a problem. Shorthands (called symbolic links) in Linux OS is very widely used and is a feature that should be advertised for saving time/money and not something to be hidden from users.

@gibson042
Copy link
Member Author

@gibson042 gibson042 commented Jul 6, 2016

The most important point is backward compatibility. Users should not have to keep modifying their code (and every jquery plugins they used), everytime a new jquery major version is released.

Breaking backwards compatibility is precisely the reason for releasing a new major version. Not every user will have to modify code, but it is a guarantee that at least some will. So please consider this a strong suggestion to avoid event shorthand methods in all new code.

@markelog markelog added the Docs label Jul 7, 2016
@markelog
Copy link
Member

@markelog markelog commented Jul 7, 2016

I think there is confusion about term "deprecating".

Let's go to the wikipedia page for the definition -

Deprecation is the discouragement of use of some feature, design or practice, typically because it has been superseded or is no longer considered safe, without (at least for the time being) removing it from the system of which it is a part or prohibiting its use.

without removing - purpose of tickets like that is only to discourage use of it. Nothing more. For example, DOM method window.unescape is deprecated, but it is not removed until browser vendors will be sure (based on their usage stats) that no one is no longer using it aka "Not to break a web" principle.

We could use same rule - not remove those widely used methods until no one uses them with newer version of jQuery, meanwhile, if we unfavor this practise we should show it. That's all it is.

Not the first time i see this misconception which really sadness me, i urge everyone to see formal limitations of this term.

@mgol
Copy link
Member

@mgol mgol commented Jul 7, 2016

Can we move it to 3.2.0? 3.1.0 is almost ready (in fact, I moved all issues previously assigned to 3.1.0 to 3.2.0).

@timmywil
Copy link
Member

@timmywil timmywil commented Jul 7, 2016

@markelog A formal definition has little bearing on the popular connotations associated with a term, which is why dictionaries change with time. Your point does not change my belief that "deprecation" implies eventual removal, at least to some. I wish there was a way we could say that we recommend avoiding a particular API, which is different than saying we recommend avoiding it and it may be removed in a future version.

@mgol
Copy link
Member

@mgol mgol commented Jul 7, 2016

@timmywil How about if we changed the name of the deprecated module to discouraged and moved there stuff that we don't want to remove due to widespread usage but we still recommend to avoid? This module would be then excluded from the slim build which may urge library creators to avoid those APIs for real.

@dmethvin
Copy link
Member

@dmethvin dmethvin commented Jul 7, 2016

Yeah if we're not going to use Deprecated for these then we should come up with another term. We've got quite a few of these "Deprecate X" issues open and they seem to be blocked on coming to an agreement about this.

@markelog
Copy link
Member

@markelog markelog commented Jul 7, 2016

@timmywil

Your point does not change my belief that "deprecation" implies eventual removal, at least to some

It does imply that to some because it is a first step in removal process, there isn't any other way really, we can call any way we prefer - discouraged, abandoned or expecto patronum or something.

It wouldn't change the meaning of what we are doing which is discouraging people from using it, so it still would be the first step in removal process

@mgol
Copy link
Member

@mgol mgol commented Jul 7, 2016

I actually don't think deprecation must mean plans to remove in the nearby future. I would say, though, that deprecating sth means we discourage using it and we'd love to remove it but who knows if and when the removal will be possible. If we don't want to remove it not due to widespread usage but just because we think this API should continue to exist then why would we discourage using it? Those two things don't really go hand in hand with each other.

Applying that to this ticket, I'd say that since we want to discourage it, we should deprecate it even if we can only remove it in 5 or 10 years.

@markelog
Copy link
Member

@markelog markelog commented Jul 7, 2016

That's exactly what i'm trying to say, thank you

@dmethvin
Copy link
Member

@dmethvin dmethvin commented Jul 7, 2016

There is some precedent for long deprecation. We deprecated jQuery.browser in 1.3 but didn't remove it until 1.9. In that case we also got a lot of complaints about the deprecation.

The main issue here is that the longer we wait to send the signal "this isn't best practice anymore" using whatever word, the longer it will take for people to change their code because they're not aware of it. Just like jQuery.browser there will be people who disagree with whether something is good practice or not, and there may be a lot of code out there using it. That can affect when we remove it.

@timmywil timmywil modified the milestones: 3.2.0, 3.1.0 Jul 7, 2016
@BillJones50
Copy link

@BillJones50 BillJones50 commented Jul 7, 2016

Is there a particular reason some Jquery members want to actively discourage using shorthands?

The only reason I can think of is reducing file size (by eventually removing it - whenever that would be).

So I did actual calculations and after minify+Gzip, it only saves around 400 bytes. Is there any other reason?

@scottgonzalez
Copy link
Member

@scottgonzalez scottgonzalez commented Jul 7, 2016

Is there any other reason?

#3214 (comment)

@lpd-au
Copy link

@lpd-au lpd-au commented Nov 6, 2017

If these shorthands aren't likely to ever be removed, why not wait for a major version (and new version of jQuery migrate) to deprecate them?

@mgol
Copy link
Member

@mgol mgol commented Nov 6, 2017

@lpd-au Waiting for a major version wouldn't help in reducing usage of these shorthands. Besides, according to semver deprecations are free to land in minor releases.

@lpd-au
Copy link

@lpd-au lpd-au commented Nov 6, 2017

Just because they can, doesn't mean they always should. Especially the .click(function) being such a widely used part of the library, the canonical example to show jQuery's elegance over native JS, which isn't documented anywhere as being in bad style. There is no rush here to deprecate for later removal in an imminent major release, which is probably why it's already been pushed back from 3.1.0 to 3.2.0 to 3.3.0... can we just make the wait official? How do you expect usage to fall anyway among developers who already transitioned to jQ3 and removed the migration plugin?

@dmethvin
Copy link
Member

@dmethvin dmethvin commented Nov 6, 2017

Nothing has broken because of this deprecation. It doesn't make sense to undeprecate the feature just to get rid of a warning in Migrate. You can either ignore the warning or override jQuery.fn.click() after loading Migrate to get rid of it. Or, change the code generating the warning.

@lpd-au
Copy link

@lpd-au lpd-au commented Nov 6, 2017

Undeprecate? What am I missing here... the issue is still open, marked for an unreleased milestone and isn't documented anywhere that I can find?

@timmywil
Copy link
Member

@timmywil timmywil commented Nov 6, 2017

I think it's safe to deprecate in the next version. It's not getting removed so no code will be broken.

@RinkAttendant6
Copy link

@RinkAttendant6 RinkAttendant6 commented Jun 19, 2018

Is there any particular reason that these deprecations are not documented here: https://api.jquery.com/category/deprecated/deprecated-3.3/
Nor are they documented on the API documentation pages for the functions (for example https://api.jquery.com/change/)

@mgol
Copy link
Member

@mgol mgol commented Jun 20, 2018

@RinkAttendant6 See jquery/api.jquery.com#972. Someone needs to do the work to document it, we haven't gotten to it, yet. Contributions are welcome!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

10 participants
You can’t perform that action at this time.