-
Notifications
You must be signed in to change notification settings - Fork 6
Comparing Import and With
Shane Brinkman-Davis Delamore edited this page Mar 29, 2018
·
8 revisions
My concept of import is similar to JavaScript's built-in with. I know with is maligned, but I think with can be rehabilitated with slightly different semantics:
- CaffeineScript's
importis resolved be implemented as a load-time cost, not a runtime cost. Essentially, there should be little or no practical performance hit. If needed, it could potentially be computed at compile-time.
Pros, cons, thoughts:
- Since you can always view the generated javascript, CaffeineScript's
importshould be easier to understand. -
importbest practices-
importshould only be used at load time -
importshould only be used with plain objects
-
- arguments against
with - Most of these 'bad' examples are just bad uses of
with. As with all powerful tools, including most programming constructs, you can shoot yourself in your foot if you use them incorrectly. - Not-future-proof is the most interesting example in the link above.
- Even if you use the
importbest-practices from above you could still be susceptible to breakage due to language or library changes. - However, good code should never access globals - the values set on window/self/global - except for those defined by the EcmaScript standard.
- Such code, using
import, is only susceptible to breakage if the EcmaScript standard or a library removes a property or completely redefines it. - In either case, code without
importwould be just as susceptible to future breakage
- Even if you use the
- Home
- Get Started
- Benefits
- Highlights
- Productivity by Design
- CaffeineScript Design
- What is CaffeineScript Good For?
- Get the most out of JavaScript
- Language Comparison
- CHANGELOG
- Blocks Instead of Brackets
- Binary Line-Starts
- Everything Returns a Value
- Streamlined Modules
- Scopes and Variables
- Optional Commas
- Semantics
- Ambiguities