Javascript: Renaming built in functions [closed]












0















In Javascript, is it acceptable to rename built in functions. For example, in my code, I use document.querySelector() tons of times. This is extremely long and tedious to type every single time (even with autocomplete from the IDE's side). Therefore, I decided to create a new function with a shorter name like the following:



let qs = selector => document.querySelector(selector);



Is this an acceptable practice in the JS community? Is this considered bad code? If so, why? Additionally, if doing this is alright, what are some drawbacks?



Thanks.










share|improve this question













closed as primarily opinion-based by Carcigenicate, Billal Begueradj, Umair, Sahil Mahajan Mj, Grimthorr Nov 16 '18 at 12:12


Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.



















  • It's fine (it's more DRY, after all, which is almost always good), though I'd highly recommend const by default rather than let

    – CertainPerformance
    Nov 16 '18 at 3:28













  • One drawback I can think of: it's going to be a stumbling block for someone new to the codebase.

    – ceejayoz
    Nov 16 '18 at 3:30











  • @CertainPerformance However, what exactly do you mean by "dry"? And yes, i meant const, not let :) Thanks for the quick reply.

    – Yang K
    Nov 16 '18 at 3:30











  • @ceejayoz thanks for the reply. it's a pretty small codebase (less than 10,000 LoC), so not sure that it would be big deal.

    – Yang K
    Nov 16 '18 at 3:31











  • @YangK "Dry" is short for "do not repeat yourself". Basically DRY = less repetition in your code, which is almost always a positive.

    – Carcigenicate
    Nov 16 '18 at 3:57


















0















In Javascript, is it acceptable to rename built in functions. For example, in my code, I use document.querySelector() tons of times. This is extremely long and tedious to type every single time (even with autocomplete from the IDE's side). Therefore, I decided to create a new function with a shorter name like the following:



let qs = selector => document.querySelector(selector);



Is this an acceptable practice in the JS community? Is this considered bad code? If so, why? Additionally, if doing this is alright, what are some drawbacks?



Thanks.










share|improve this question













closed as primarily opinion-based by Carcigenicate, Billal Begueradj, Umair, Sahil Mahajan Mj, Grimthorr Nov 16 '18 at 12:12


Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.



















  • It's fine (it's more DRY, after all, which is almost always good), though I'd highly recommend const by default rather than let

    – CertainPerformance
    Nov 16 '18 at 3:28













  • One drawback I can think of: it's going to be a stumbling block for someone new to the codebase.

    – ceejayoz
    Nov 16 '18 at 3:30











  • @CertainPerformance However, what exactly do you mean by "dry"? And yes, i meant const, not let :) Thanks for the quick reply.

    – Yang K
    Nov 16 '18 at 3:30











  • @ceejayoz thanks for the reply. it's a pretty small codebase (less than 10,000 LoC), so not sure that it would be big deal.

    – Yang K
    Nov 16 '18 at 3:31











  • @YangK "Dry" is short for "do not repeat yourself". Basically DRY = less repetition in your code, which is almost always a positive.

    – Carcigenicate
    Nov 16 '18 at 3:57
















0












0








0








In Javascript, is it acceptable to rename built in functions. For example, in my code, I use document.querySelector() tons of times. This is extremely long and tedious to type every single time (even with autocomplete from the IDE's side). Therefore, I decided to create a new function with a shorter name like the following:



let qs = selector => document.querySelector(selector);



Is this an acceptable practice in the JS community? Is this considered bad code? If so, why? Additionally, if doing this is alright, what are some drawbacks?



Thanks.










share|improve this question














In Javascript, is it acceptable to rename built in functions. For example, in my code, I use document.querySelector() tons of times. This is extremely long and tedious to type every single time (even with autocomplete from the IDE's side). Therefore, I decided to create a new function with a shorter name like the following:



let qs = selector => document.querySelector(selector);



Is this an acceptable practice in the JS community? Is this considered bad code? If so, why? Additionally, if doing this is alright, what are some drawbacks?



Thanks.







javascript renaming






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 3:28









Yang KYang K

678




678




closed as primarily opinion-based by Carcigenicate, Billal Begueradj, Umair, Sahil Mahajan Mj, Grimthorr Nov 16 '18 at 12:12


Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.









closed as primarily opinion-based by Carcigenicate, Billal Begueradj, Umair, Sahil Mahajan Mj, Grimthorr Nov 16 '18 at 12:12


Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.















  • It's fine (it's more DRY, after all, which is almost always good), though I'd highly recommend const by default rather than let

    – CertainPerformance
    Nov 16 '18 at 3:28













  • One drawback I can think of: it's going to be a stumbling block for someone new to the codebase.

    – ceejayoz
    Nov 16 '18 at 3:30











  • @CertainPerformance However, what exactly do you mean by "dry"? And yes, i meant const, not let :) Thanks for the quick reply.

    – Yang K
    Nov 16 '18 at 3:30











  • @ceejayoz thanks for the reply. it's a pretty small codebase (less than 10,000 LoC), so not sure that it would be big deal.

    – Yang K
    Nov 16 '18 at 3:31











  • @YangK "Dry" is short for "do not repeat yourself". Basically DRY = less repetition in your code, which is almost always a positive.

    – Carcigenicate
    Nov 16 '18 at 3:57





















  • It's fine (it's more DRY, after all, which is almost always good), though I'd highly recommend const by default rather than let

    – CertainPerformance
    Nov 16 '18 at 3:28













  • One drawback I can think of: it's going to be a stumbling block for someone new to the codebase.

    – ceejayoz
    Nov 16 '18 at 3:30











  • @CertainPerformance However, what exactly do you mean by "dry"? And yes, i meant const, not let :) Thanks for the quick reply.

    – Yang K
    Nov 16 '18 at 3:30











  • @ceejayoz thanks for the reply. it's a pretty small codebase (less than 10,000 LoC), so not sure that it would be big deal.

    – Yang K
    Nov 16 '18 at 3:31











  • @YangK "Dry" is short for "do not repeat yourself". Basically DRY = less repetition in your code, which is almost always a positive.

    – Carcigenicate
    Nov 16 '18 at 3:57



















It's fine (it's more DRY, after all, which is almost always good), though I'd highly recommend const by default rather than let

– CertainPerformance
Nov 16 '18 at 3:28







It's fine (it's more DRY, after all, which is almost always good), though I'd highly recommend const by default rather than let

– CertainPerformance
Nov 16 '18 at 3:28















One drawback I can think of: it's going to be a stumbling block for someone new to the codebase.

– ceejayoz
Nov 16 '18 at 3:30





One drawback I can think of: it's going to be a stumbling block for someone new to the codebase.

– ceejayoz
Nov 16 '18 at 3:30













@CertainPerformance However, what exactly do you mean by "dry"? And yes, i meant const, not let :) Thanks for the quick reply.

– Yang K
Nov 16 '18 at 3:30





@CertainPerformance However, what exactly do you mean by "dry"? And yes, i meant const, not let :) Thanks for the quick reply.

– Yang K
Nov 16 '18 at 3:30













@ceejayoz thanks for the reply. it's a pretty small codebase (less than 10,000 LoC), so not sure that it would be big deal.

– Yang K
Nov 16 '18 at 3:31





@ceejayoz thanks for the reply. it's a pretty small codebase (less than 10,000 LoC), so not sure that it would be big deal.

– Yang K
Nov 16 '18 at 3:31













@YangK "Dry" is short for "do not repeat yourself". Basically DRY = less repetition in your code, which is almost always a positive.

– Carcigenicate
Nov 16 '18 at 3:57







@YangK "Dry" is short for "do not repeat yourself". Basically DRY = less repetition in your code, which is almost always a positive.

– Carcigenicate
Nov 16 '18 at 3:57














1 Answer
1






active

oldest

votes


















3














No.
Someone is going to come behind you to edit your code.
They will then have to track down your renaming function to actually see what it does.
Create an snippet in your IDE if it’s that much of an issue for you.






share|improve this answer



















  • 1





    Thanks mate. This is exactly what I was wondering about :)

    – Yang K
    Nov 16 '18 at 3:34











  • No problem at all!

    – Ryan
    Nov 16 '18 at 3:35


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














No.
Someone is going to come behind you to edit your code.
They will then have to track down your renaming function to actually see what it does.
Create an snippet in your IDE if it’s that much of an issue for you.






share|improve this answer



















  • 1





    Thanks mate. This is exactly what I was wondering about :)

    – Yang K
    Nov 16 '18 at 3:34











  • No problem at all!

    – Ryan
    Nov 16 '18 at 3:35
















3














No.
Someone is going to come behind you to edit your code.
They will then have to track down your renaming function to actually see what it does.
Create an snippet in your IDE if it’s that much of an issue for you.






share|improve this answer



















  • 1





    Thanks mate. This is exactly what I was wondering about :)

    – Yang K
    Nov 16 '18 at 3:34











  • No problem at all!

    – Ryan
    Nov 16 '18 at 3:35














3












3








3







No.
Someone is going to come behind you to edit your code.
They will then have to track down your renaming function to actually see what it does.
Create an snippet in your IDE if it’s that much of an issue for you.






share|improve this answer













No.
Someone is going to come behind you to edit your code.
They will then have to track down your renaming function to actually see what it does.
Create an snippet in your IDE if it’s that much of an issue for you.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 16 '18 at 3:31









RyanRyan

911313




911313








  • 1





    Thanks mate. This is exactly what I was wondering about :)

    – Yang K
    Nov 16 '18 at 3:34











  • No problem at all!

    – Ryan
    Nov 16 '18 at 3:35














  • 1





    Thanks mate. This is exactly what I was wondering about :)

    – Yang K
    Nov 16 '18 at 3:34











  • No problem at all!

    – Ryan
    Nov 16 '18 at 3:35








1




1





Thanks mate. This is exactly what I was wondering about :)

– Yang K
Nov 16 '18 at 3:34





Thanks mate. This is exactly what I was wondering about :)

– Yang K
Nov 16 '18 at 3:34













No problem at all!

– Ryan
Nov 16 '18 at 3:35





No problem at all!

– Ryan
Nov 16 '18 at 3:35



這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini