Fork me on GitHub
#clojurescript
<
2019-02-11
>
myguidingstar13:02:22

it works in Clojure but Cljs compiler yells "Use of undeclared Var <some namespace>/Number"

thheller13:02:49

js/Number or number should work

myguidingstar13:02:18

what about Boolean and String?

myguidingstar13:02:21

and why is so?

thheller13:02:24

same for boolean/string

thheller13:02:16

protocols are first checked on the type itself. if not found it checks typeof(thing) which returns string, array, object, boolean, etc for JS

thheller13:02:49

but protocols on native types can be a bit wonky depending on the JS engine

thheller13:02:57

IE had troubles with that in the past

thheller13:02:13

safari too IIRC but I think that was a long time ago

myguidingstar13:02:41

thanks, I'm trying it now

grounded_sage16:02:29

I’ve been really interested in network transfer size lately and have noticed there is a rather large default size for cljs code aimed at the browser (haven’t tested node). I did a console log hello world using figwheel main and it was like 5.5kb. Cljs.core I believe is around 30kb which is what one would expect when using a bunch of cljs features and libraries. Using Preact and other @developit libraries people have created whole PWA’s for as little as 14kb. I personally believe in using a tool that understands the entire application and optimises based on that is the best way to go. So I am quite impressed with what I read over on Elm https://elm-lang.org/blog/small-assets-without-the-headache I haven’t delved too much into it but my assumption is that these libraries are smaller based on using modern/new JS features. I’m curious if GCC has any flags or plans to use modern JS features if this is the case. Is it possible for cljs to compete on smaller file sizes for very very small applications?

thheller16:02:46

GCC is already substantially better than ALL other JS tools and supports pretty much all modern features

thheller16:02:28

cljs.core will always be used in any real application and that includes the immutable data structures

thheller16:02:57

so when comparing it to JS builds compare it to something using immutable-js + lodash or so

thheller16:02:18

use of any modern JS features will not affect the size in any meaningful way

thheller16:02:56

so no CLJS won't compete on those very very small applications

thheller16:02:15

the closure compiler pretty much already does what the elm post describes and soooo much more

thheller16:02:30

(don't get confused by the 5.5kb min size, that is just not a case we optimize for. it would literally be console.log("hello world") if we did)

dnolen16:02:21

@grounded_sage I would consider ~30K to be pretty small, given that most other assets will be much larger, if you stick with Google Closure this is actually not that hard to achieve

dnolen16:02:06

IMO CLJS is actually pretty great for doing simple static sites where you need a little bit of scripting

johnj20:02:04

@dnolen Why would you bother with cljs for a little bit of scripting if you are not using react? honest newbie question

dnolen20:02:36

because I would rather write that in ClojureScript instead of JavaScript? 🙂

dnolen20:02:35

I'm pretty comfortable with JS, but ClojureScript just has a lot affordances

dnolen20:02:45

plus anything basic I want is in Google Closure

dnolen20:02:29

if I write in JavaScript then builds are often more verbose, and you have to go find dependencies etc.

dnolen20:02:47

surprisingly I find ClojureScript cognitively less overhead than modern JavaScript for simple stuff

grounded_sage20:02:07

Definitely cljs is much nicer to write in. React sometimes isn’t necessary I’ve been creating static sites in Rum using React but sometimes React isn’t needed so was writing scripts. Been doing a lot of vanilla JS scripts because some pages I get down to less than 10kb. Excluding images of course.

johnj20:02:12

I see, so is common to leverage the closure lib?

jimberlage20:02:37

The closure lib is hard to find documentation for, but it’

jimberlage20:02:43

it’s pretty good.

johnj20:02:54

@dnolen but yeah, although 2019 JS is much better than it used to be (Object.fromEntries, etc..) it is no Clojure 😉

jimberlage20:02:01

The drag and drop library in goog.fx is nice

lilactown20:02:42

anything of nominal complexity I appreciate having Clojure data structures + standard library

lilactown20:02:47

even if I'm not using React

johnj20:02:49

@jimberlage good to know, I though it was mostly used only for namespace stuff

dnolen20:02:23

exactly if I would have to cobble together a couple of JavaScript libs and write more than 200 lines, then I'm gonna use ClojureScript instead

grounded_sage20:02:30

From what I can tell from looking at things in the wild and playing around with them a little. You can keep a JS app even something quite complex relatively small much smaller than what can be made in cljs. Though it bloats much more quickly. Especially once you head north of 100kb JS.

dnolen20:02:35

so that's pretty much anything that isn't completely trivial

dnolen20:02:31

@grounded_sage that's never been my experience and I know JavaScript pretty well

dnolen20:02:09

not without hand picking every (micro)lib anyway, or relying very heavily on very modern JavaScript (implementation) which still isn't that practical IMO

lilactown20:02:36

if bundle size is one of your top requirements, and you're willing to invest heavily in pruning and picking and writing code that is optimized very well for JS bundlers/minifiers, then CLJS will not be your best solution

dnolen20:02:56

I just disagree

dnolen20:02:06

people built websites with jQuery for over a decade

dnolen20:02:08

and still do

dnolen20:02:19

if jQuery is small enough, ClojureScript is small enough

lilactown20:02:33

but if it's a middling concern, I find CLJS provides much better bang-for-buck in terms of how much I have to think about code size vs. what I get

dnolen20:02:40

if all your assets are magically tiny

dnolen20:02:43

which isn't possible

dnolen20:02:01

anyways - the microlib thing was a fad as far as I'm concerned

dnolen20:02:09

but the pendulum has swung the other way with React

dnolen20:02:21

where one deps means mb of JS

grounded_sage20:02:23

Yea it does take way more work to keep it small in vanilla JS. Something I’m not really interested in which is why I was curious.

lilactown20:02:36

I also think about how the impact on the UX is not linear w.r.t. bundle size

grounded_sage20:02:37

Preact is doing quite well IMO. I saw something about Uber having a ~50kb app build on Preact.

john20:02:11

I can't think of many JS apps I'd need to write that would be severely hampered by a few hundred KB of cljs deps

johnj20:02:28

what is the size of a hello world react with cljs (rum or reagent) ?

dnolen20:02:05

ClojureScript baseline is like 25K, and you go up from there with each lib you add

johnj20:02:00

ah nice, sounds pretty good for a pure cljs (with react) in my case

dnolen20:02:23

ClojureScript benefits from DCE, but the mileage is still a bit variable if it's not Closure stuff, but it's definitely better than anything in JS except for probably Rollup

grounded_sage20:02:37

I think React is 35kb at the moment? So that’s like 60kb @lockdown- then there is Reagent as a lib which I don’t think would add much.

lilactown20:02:13

I have a moderately complex app that uses a few libraries: React, react-grid-layout, re-frame. it's 100kb un-gzipped

grounded_sage20:02:49

What does that gzip to @lilactown?

dnolen20:02:51

@grounded_sage we're only talking about gzipped

dnolen20:02:38

oh sorry I see that @lilactown mentioned his app

grounded_sage20:02:51

Yea I know. He said un-gzipped.

thheller21:02:05

IMHO code-splitting (aka :modules) is still very underused which solves pretty much all size issues since you can delay loading until required

johnj21:02:18

@grounded_sage Up to 150Kb (for mobile) would be good for me, just planning to enhance a web app, not sure if going with react or not, react makes things simpler even for little enhancements I guess

john21:02:05

You know what might be interesting... a version of code splits where you can keep an existing compiler env cached for later compiles, so that future modules can depend on the same cljs-base.js... then you could cache your app's base for longer and newer updates could just layer on super-minified updates.

dnolen21:02:51

@tundawork1 something like that is already possible

dnolen21:02:04

Google Closure supports reusing names across different builds

dnolen21:02:09

this means base is unlikely to change

john21:02:21

Like, if you just keep a compiler watch going?

dnolen21:02:28

across builds

dnolen21:02:31

doesn't matter when you build

grounded_sage21:02:42

Yea if I am building something with a bit of complexity or is an unknown/uncontained domain I would definitely use CLJS all the way. But for really small stuff I think JS maybe even Elm might be better in some cases.

john21:02:10

@dnolen can you give me a pointer on more info there? I'm banging on a bunch of code-split stuff atm and it might be a worthwhile exploration

lilactown21:02:28

the gzip didn't show in the headers, but I doubted myself so I actually pulled it down and looked on disk how big it was

john21:02:48

ah that's cool

lilactown21:02:25

how should I handle unknown tags when reading EDN?

lilactown22:02:00

I’d like to just pass them through, but I’m not sure how to do that with cljs.tools.read.edn

john22:02:26

@lilactown I recall there being relevant information here: http://insideclojure.org/2018/06/21/tagged-literal/

lilactown22:02:47

very interesting. thanks!

lilactown22:02:08

yep, that pretty much does exactly what I want 😄