-
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
import
is 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
import
should be easier to understand. -
import
best practices-
import
should only be used at load time -
import
should 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
import
best-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
import
would 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