These are chat archives for mithriljs/mithril.js

12th
Jan 2018
josiahking
@josiahking
Jan 12 00:15
Hi @/all when mithril is installed via npm, must it be run in a node server for the m.request to work. I am currently following the example on https://mithril.js.org/installation.html When i tried to use the m.request, i get this error: Cross-Origin Request Blocked. I am accessing the app like this file:///C:/workspace/path/to/directory/index.html
Pat Cavit
@tivac
Jan 12 00:16
file:/// URLs can't make remote requests iirc
josiahking
@josiahking
Jan 12 00:17
ok
What do i do ? @tivac , should i run it as a node server or any server will be fine.
Pat Cavit
@tivac
Jan 12 00:19
Yup, install one of the many simple node server scripts & access it via http:// instead
josiahking
@josiahking
Jan 12 00:19
ok thanks will do that.
Dominik Dumaine
@Bondifrench
Jan 12 03:20
Nice to see Mithril being mentioned in this very lengthy blog The Complete Guide to Deploying Javascript Applications from Auth0
John Emhoff
@JohnEmhoff
Jan 12 05:23
Mithril's my first SPA framework -- seems pretty similar to React, only a saner surface area. What does React offer that Mithril doesn't?
Scotty Simpson
@CreaturesInUnitards
Jan 12 06:02
79 more minutes to get from 0 to hello world 😜
Pat Cavit
@tivac
Jan 12 06:03
big company backing it
huge community
lots and lots of articles/resources/SO questions/etc
John Emhoff
@JohnEmhoff
Jan 12 06:04
but on the technical side?
James Forbes
@JAForbes
Jan 12 06:04
browser api normalization
Pat Cavit
@tivac
Jan 12 06:05
Error catching in template logic annnnd... yeah browser event stuff
James Forbes
@JAForbes
Jan 12 06:06
certain tools/products rely on it's API, e.g. zeit/next, react native, probably others
I mean there are other libraries that work with zeit/next thanks to the community, but react is sort of a support assumption now
John Emhoff
@JohnEmhoff
Jan 12 06:07
cool, thanks
seems like stuff outside of the core needs of a webapp
Pat Cavit
@tivac
Jan 12 06:08
I love mithril's API, size, perf, and community so I use it over react every time
James Forbes
@JAForbes
Jan 12 06:08
yeah exactly
Pat Cavit
@tivac
Jan 12 06:09
but there are lots of useful things about react, especially the massive community & resources out there
James Forbes
@JAForbes
Jan 12 06:09
^
Pat Cavit
@tivac
Jan 12 06:09
stuff like create-react-app
which lol mithril doesn't need because its tooling story isn't a nightmare
but you know
James Forbes
@JAForbes
Jan 12 06:09
there's no technical reason mithril can't have those things, it's just community/backing etc
Pat Cavit
@tivac
Jan 12 06:09
yup
James Forbes
@JAForbes
Jan 12 06:09
but this community is brimming with lots of brilliant stuff
e.g. j2c, mithril-query, wright, bss to name a few
and mithril also doesn't need as much tooling, partly because it doesn't encourage the use of jsx
so create-mithril-app might be, put a script tag in a html file, honestly
Pat Cavit
@tivac
Jan 12 06:11
lol right
James Forbes
@JAForbes
Jan 12 06:18
lol someone should make that
actually reading everything it does there's lot of great stuff in there
Pat Cavit
@tivac
Jan 12 06:21
yeah it's a cool idea & a smart implementation
sounds like webpack4 will reduce the need for it though
since it'll be configless by default
James Forbes
@JAForbes
Jan 12 06:21
oh really, haven't be keeping up with it, that's great
Pat Cavit
@tivac
Jan 12 06:22
yeah, supporting dynamic import chunking and everything
should be interesting
I've been a rollup lover forever but that might be enough to get me to switch
James Forbes
@JAForbes
Jan 12 06:22
but yeah, it's rare we hear from people that it's hard to get up and running. Most questions we get from beginners are state management from what I've observed.
Pat Cavit
@tivac
Jan 12 06:22
I just wish the webpack APIs were better, I hate updating modular-css to work w/ it
James Forbes
@JAForbes
Jan 12 06:24
I'll give you my browserify when you pry it from my cold, dead hands :D
Pat Cavit
@tivac
Jan 12 06:32
eugh
so many wasted functions
James Forbes
@JAForbes
Jan 12 06:32
wasted functions?
Pat Cavit
@tivac
Jan 12 06:32
all the commonjs wrappers
James Forbes
@JAForbes
Jan 12 06:32
oh you mean tree shaking
Pat Cavit
@tivac
Jan 12 06:33
scope hoisting
also browserify is almost as bad as webpack
fuckin streams everywhere
you sir are incorrect :D
Pat Cavit
@tivac
Jan 12 06:35
use what makes you happy dude, having dived deep into browserify's guts once I'm happy to stay far away
James Forbes
@JAForbes
Jan 12 06:35
haha ok
justb
@justb
Jan 12 06:36
Uncaught TypeError: Cannot read property 'indexOf' of undefined, when i use m.route.param in oninit,
Does anyone know why?
Pat Cavit
@tivac
Jan 12 06:37
can you recreate on http://flems.io/mithril or jsbin or something?
justb
@justb
Jan 12 06:58
Not yet, i used it well before, this time i use m.route.param twice
Barney Carroll
@barneycarroll
Jan 12 07:14

@JAForbes @tivac create react app is…

Hot take incoming. Duck.

…bad, actually

Create react app is on par with Redux where there's a strong argument to making the disclaimers more visible than the contents.
Rasmus Porsager
@porsager
Jan 12 07:33
@tivac re rollup, did you see: rollup/rollup#1841 ?
Pat Cavit
@tivac
Jan 12 07:33
YES
I watch the rollup repo so I've been eying guybedford's work closely
@barneycarroll what's your beef with CRA?
Barney Carroll
@barneycarroll
Jan 12 07:39
The disparity between "it just works" and "this is too complicated for me" comes back to bite harder if and when you need to unbox it
Pat Cavit
@tivac
Jan 12 07:40
ah, that's fair
I don't use it for multiple reasons, but one of the big ones is that I want to know how all my tools work
because I'm insane
for folks who just need to get something done it seems like a real nice assist though
Barney Carroll
@barneycarroll
Jan 12 07:44
I know I'm an angry old man yelling at clouds but I really don't like the way React implicitly divides the world into 2 classes: people who understand angle brackets and people who understand package json
Rasmus Porsager
@porsager
Jan 12 07:45
@tivac Ah, I should do that, only saw this one by accident.. It's really cool to see how it's so active again, with the work from guybedford and lucastaegert.. I actually thought it wouldn't go any further after rich stopped working on it.
Pat Cavit
@tivac
Jan 12 07:45
yeah they've been killin it
Barney Carroll
@barneycarroll
Jan 12 07:46
@porsager same, this is pleasantly unexpected. I made to reach for Rollup a few months ago and came away with the impression it was dead.
Pat Cavit
@tivac
Jan 12 07:47
I was never able to dedicate the time to learning more of rollup's internals that I wanted to
got the plugin API some good updates though while working on modular-css so I'm proud of that
Rasmus Porsager
@porsager
Jan 12 07:48
@tivac yeah that was great! I also tried a bit, but got stuck at grokking magicstring 😋
Pat Cavit
@tivac
Jan 12 07:49
hahaha magic-string is a really bonkers idea that somehow works out ok
Rasmus Porsager
@porsager
Jan 12 07:49
Apparently 😃 Still want to give it a bit more time
Pat Cavit
@tivac
Jan 12 07:49
talking about this makes me want to carve out time to try and help out rollup
especially now that dynamic import and code-splitting look likely to land
I don't have a ton of use ATM for either (game UI lololol) but I want 'em, if only for keeping rollup as a nice small alternative to the webpack insanity
:zzz: :wave:
Rasmus Porsager
@porsager
Jan 12 07:52
I think rollup needs a sister project with preloaded plugins and 0 config that works for the usual setup..
That would be nice tivac.. It's ok to have hobbies 😉
Sleep tight
Rasmus Porsager
@porsager
Jan 12 09:11
Hmm.. until now the addition of class to js could just be ignored, no harm done - but now it's suddenly the catalyst for recommending we must litter semicolons everywhere :-(
Patrik Johnson
@orbitbot
Jan 12 09:15
class requires semicolons?
must have missed the memo
Rasmus Porsager
@porsager
Jan 12 09:16
the public fields proposal specifically adds extra cases.. tc39/ecma262#1062
Patrik Johnson
@orbitbot
Jan 12 09:18
hmm, Leo's commenting on the edit
Rasmus Porsager
@porsager
Jan 12 09:18
Yeah, that was fun to see :P
Hope they consider his points..
Patrik Johnson
@orbitbot
Jan 12 09:30
ah, so it's only inside the class definition body where you'd like to have a instance or static field that you need to use the semicolons?
Rasmus Porsager
@porsager
Jan 12 10:03
Exactly, but based on that they want to make it a recommendation to not rely on ASI generally. Seemed to me that's what spurred it at least. Relying on ASI or not, I think Leo's comment is on point, that semi colon rules need to be specified no matter what, so why take a stance on how people use it.
Patrik Johnson
@orbitbot
Jan 12 10:14
:+1:
just started playing around with kotlin on android, and after not using semicolons in swift or js for a while it's a bit strange how a small detail like that starts to reduce visual clutter
not that it really matters that much, more of a feel thing
Rasmus Porsager
@porsager
Jan 12 10:18
Yeah, that's exactly the feeling I get when I look at a codebase with semicolons.. Not sure if it's just because I'm not used to it now, or if it's actually because there's "less symbols" :P I'm also in the same boat wrt. swift..
Barney Carroll
@barneycarroll
Jan 12 10:21
I've been playing with commas everywhere since Chrome started tolerating trailing commas in function calls, signature expressions, arrays and objects…
I'm not sure if it's just as irritating yet
Miguel Espinoza
@purefan
Jan 12 10:27
hello everyone! Getting started with mithriljs and even after reading the docs I cant get some things to work, for example, I want to fetch settings from a database, the library uses a promise, in my component's oninit method I declare the settings object and when the promise resolves I update the this.settings reference but the view doesn't re-draw:
const Settings = {
  oninit: (ctrl) => {
    this.settings = [1,2,3]
    const self = this
    ctrl.attrs.database.get('settings')
      .then(settings => self.settings = settings)
  },
  view: (ctrl) => {
    return ctrl.attrs.m('div', ctrl.state.settings.map((setting) => `Setting number: ${setting}`))
  }
}
Barney Carroll
@barneycarroll
Jan 12 10:28
Mithril provides its own XHR API which will automatically redraw when a request resolves
If you're using a third party library, you'll need to explicitly redraw when the data is changed
const Settings = {
  oninit: vnode => {
    vnode.state.settings = [1,2,3]
    vnode.attrs.database.get('settings')
      .then(settings => {
        vnode.state.settings = settings)

        m.redraw()
      }
  },
  view: vnode =>
    vnode.attrs.m('div', vnode.state.settings.map((setting) => `Setting number: ${setting}`))
}
Miguel Espinoza
@purefan
Jan 12 10:30
yup, that worked! Thanks @barneycarroll !
Rasmus Porsager
@porsager
Jan 12 10:30
@barneycarroll to avoid comma first?
It's amazing gitter can lag so hard when scrolling and there's code blocks in the view.
Barney Carroll
@barneycarroll
Jan 12 10:32
@purefan BTW I didn't notice at first but there were a few reference errors in that code, I've edited the snippet to address them.
  1. There is no more ctrl in Mithril v1, the argument provided to all lifecycle methods is vnode
  2. this to reference component state will only work in 'fat' functions (not arrow functions) - the safest thing is simply to reference vnode.state
Rasmus Porsager
@porsager
Jan 12 10:33
Does anyone transpile code for use with older node versions? We have some legacy hardware that only works up to node 5.
Barney Carroll
@barneycarroll
Jan 12 10:33
@porsager I've never really understood comma-first
It seems to suggest every item in sequence should be prefixed to indicate it's in a sequence, except the first item, which is different because reasons
Miguel Espinoza
@purefan
Jan 12 10:34

Another thing, in many articles I read about a controller but was that removed in the 0.2.x series? I tried something like this which didn't work:

const Test = {
  controller: vnode => console.log('Triggered the controller'),
  view: vnode => 'whatever'
}

(by "didnt work" I mean the console.log doesn't trigger)

Barney Carroll
@barneycarroll
Jan 12 10:35
@purefan yeah, controller function has been replaced with oninit
Miguel Espinoza
@purefan
Jan 12 10:35
@barneycarroll Thanks for the clarification and all the tips! much obliged :)
Barney Carroll
@barneycarroll
Jan 12 10:36
And the ctrl object, which used to be returned / instantiated by the controller function and passed as first argument to view, has been replaced with vnode.state – now every lifecycle method on a component will get the same vnode argument
@porsager introducing trailing commas in all the places they used to be illegal feels 'more consistent' but looks silly
Miguel Espinoza
@purefan
Jan 12 10:37
Sweet! :sparkles:
Barney Carroll
@barneycarroll
Jan 12 10:38
@porsager it used to sometimes be irritating to realise you need to juggle commas when refactoring nested hyperscript expressions… But in practice although trailing commas everywhere addresses that problem, it's quite noisy
The irritating thing is that while a function invocation can contain trailing commas, simple comma operation expressions can't
I can introduce one there :point_up: , but not here :point_down:
https://github.com/barneycarroll/mle/blob/master/Node.js#L74
And if I refactor the containing expression to no longer be a function expression… Meh it feels ugly
Rasmus Porsager
@porsager
Jan 12 10:51
Ah, Yeah, I don't use comma first exclusively either.. I actually only use it for multiple variable declarations :P
I honestly haven't given comma errors any thought since I started using a linter...
I sometimes put them at their own line when doing hyperscript..
Patrik Johnson
@orbitbot
Jan 12 10:55
@purefan you might be interested in looking at the migration guide just to be aware of the differences between 0.2 and 1.x code https://mithril.js.org/change-log.html#migrating-from-v02x , it can help with keeping things clear wrt blog posts and examples online that relate to outdated syntax
Barney Carroll
@barneycarroll
Jan 12 10:56

I sometimes put them at their own line

I've started doing this for ternary expressions, it feels right

Rasmus Porsager
@porsager
Jan 12 10:56
@barneycarroll Ah, I remember seeing when you talked about using comma operation expressions in that way.. looks really neat in https://github.com/barneycarroll/mle/blob/master/Node.js :)
Patrik Johnson
@orbitbot
Jan 12 10:57
I'd do that as well for at least more complex ternaries where you can easily loose track of which part is the result
can't do comma first, it screws with my reading comprehension
Rasmus Porsager
@porsager
Jan 12 10:57

like

something
  ? true
  : false

or

something
?
true
: 
false

?

Patrik Johnson
@orbitbot
Jan 12 10:58
:point_left: a)
Rasmus Porsager
@porsager
Jan 12 10:58
Yeah I do a) as well.. I think it reads well for nested ones as well..
Patrik Johnson
@orbitbot
Jan 12 10:58
also don't really see the problems with trailing commas, don't tend to have issues with it although you can argue that there's some merit to the approach
The thing with ternaries is that personally, I rarely find them confusing unless they're nested
So anything that's consistent and consists of alternating ? : ? : ? : etc is fine… in theory. But in practice if the typesetting policy isn't quite clear you can't spot the difference
Rasmus Porsager
@porsager
Jan 12 11:02
how about with a little indentation ?
something
  ? 'yay'
  : someOtherThing
    ? 'oh'
    : someThirdThing
      ? 'right'
      : 'no way'
Barney Carroll
@barneycarroll
Jan 12 11:02
So I think operands on own line is good, but also indentation
This enables the neat construct of parentheses for grouping expressions being on the same line as the operations within them
Oscar
@osban
Jan 12 11:06
Not that my opinion matters much, but I'm with @porsager :wink:
Barney Carroll
@barneycarroll
Jan 12 11:07
@porsager your solution doesn't scale well when introducing subconditions
With my policy you can keep on adding extra possibilities to a large conditional without drifting off the right side of the page
That would only happen if there were sub-conditions
Patrik Johnson
@orbitbot
Jan 12 11:17
at face value I'm not really sure how far you "should" go with nested ternaries
zomg, just realized the ;) emoji and ;) actually winks different eyes(!)
Patrik Johnson
@orbitbot
Jan 12 11:24
winkception
Rasmus Porsager
@porsager
Jan 12 11:32
Oh you mean ؛)
:-P
Oscar
@osban
Jan 12 11:32
lol
Patrik Johnson
@orbitbot
Jan 12 11:33
initial googling didn't turn out to be relevant... :P
would of course have helped if I'd searched for semicolon instead of just colon...
Rasmus Porsager
@porsager
Jan 12 11:34
@barneycarroll that's true! Haven't had that large ones yet though :P
On first glance yours didn't feel right, but looking a third time now it's already better :P
Barney Carroll
@barneycarroll
Jan 12 11:40
@orbitbot nested conditionals should be avoided if you can but sometimes they're a hard fact of life
What I've always disagreed with is the idea that writing large nested if else statements was in any way better
The fact you can return and break and all sorts of other stuff inside those, and it's not easily visible (in fact the whole expression takes a lot more verbiage)… is a liability
Nested ternaries are much safer than the equivalent in statement form
The class specification plows deeper into hell
Patrik Johnson
@orbitbot
Jan 12 11:43
... aren't they basically going to go full squircle?
Barney Carroll
@barneycarroll
Jan 12 11:44
Classes are a great way to deal with the problems resulting from class usage
Especially if you have a natural affinity for
Classes
Rasmus Porsager
@porsager
Jan 12 11:45
:-S
Barney Carroll
@barneycarroll
Jan 12 11:46
I am so shocked by this bound arrows thing though
They're trampling over the predictable reliability of the simple & good features of ES6 in order to compensate for class's failings
Rasmus Porsager
@porsager
Jan 12 11:50
At least the weirdness stays inside their classy world.. Shouldn't hurt us classless people..
Oscar
@osban
Jan 12 12:01
I'm classless and clueless, so I should be fine ;)
spacejack
@spacejack
Jan 12 14:19
Bound arrow methods let you have the succinct clarity of class methods combined with the memory optimization of closures.
James Forbes
@JAForbes
Jan 12 14:47

@barneycarroll haha can't believe I'm doing this again :D

except the first item, which is different because reasons

First argument: "consistency be damned!"

Why does consistency matter more than less git conflicts, less pointless diffs and (previously) less runtime errors?

Reminds me of npm supporting an alias for install because they tracked a common typo isntall. So when they say npm isntall they just run npm install.

People in the thread, argued npm unisntall should alias to npm uninstall on principal.

npm/npm#6095:

Since people don't tend to mistype uninstall as unisntall (especially when rm is a much more commonly used alias), there's no need to support it, symmetry be damned.

We tend to append to lists, not replace the first item (at least that's what I've observed, or I wouldn't use it). So the first item is practically a different beast anyway.

Second argument: First is different

except the first item, which is different because reasons

head/tail, first/rest is a common distinction used in a lot of recursive algorithms.

You could easily use an alternative form e.g. rest, last. You could also intentionally mistype uninstall to make a point.

How does recursion relate to writing code? Because code is data and the way we write code tends to mimic our algorithms.

If you are queuing for a movie ticket, the person at the front of the queue can buy a movie ticket, everyone else can't.

Saying 1st and rest is a meaningless distinction is like saying trees, queues, linked lists, etc are useless data structures because the root node, or the current item, or the terminating item are the same as the rest of the structure.

/rant

Miguel Espinoza
@purefan
Jan 12 14:56
@orbitbot Thanks Patrik! definitely reading it today, I think the more "mithril code" I read the clearer things will become, for example what's common practice and what's frowned upon
Patrik Johnson
@orbitbot
Jan 12 14:57
:+1:
James Forbes
@JAForbes
Jan 12 14:58

And

something
  ? 'yay'
  : someOtherThing
    ? 'oh'
    : someThirdThing
      ? 'right'
      : 'no way'

Is like writing:

if (something ){
  'yay'
} else {
  if (someOtherThing){
    'oh'
  } else {
    if( someThirdThing ){
       'right'
    } else {
       'no way'
    }
  }
}

Sure we can write if statements that way, but it's not really easy to follow, and it's not modelling the flat series of possibilities without sub conditions that we have in our head.

Should be:

something
  ? 'yay'
: someOtherThing
  ? 'oh'
: someThirdThing
  ? 'right'
  : 'no way'

It's like chaining ||,

something
|| someOtherThing
|| someThirdThing
|| etc

Imagine if we wrote:

something
    || someOtherThing
         || someThirdThing
               || etc

Sorry @porsager, I know it was a throwaway example. I just keep seeing nested ternaries for flat conditionals all over the place.

Patrik Johnson
@orbitbot
Jan 12 15:00
@purefan if you're just picking up stuff wrt mithril, I'd suggest reading at least the Introduction, Tutorial, and Key Concepts section of the website, and then set out to skim through the rest of it (including the API section) just to understand what can be found where. flems.io/mithril is a neat place to try out stuff quickly to confirm functionality etc
Barney Carroll
@barneycarroll
Jan 12 15:03
I understand the rationale for comma first @JAForbes, I think the "first item is different" argument is debatable, we're essentially foreseeing a world where it's more likely to append to a list over time than it is to move items at the first index, which in practice is true, but again I think newline is best for large recursive structures that are liable to a lot of refactoring over time (like hyperscript)
James Forbes
@JAForbes
Jan 12 15:08
yeah I'm not against newline at all, I even tried it, I found it led to me scrolling too much, but I think that's partly the complexity of our views, data entry, with tons of messages, and validation and on and on, it's really important to see as much context as possible without scrolling.
Also, we use operator first for everything else, so comma first doesn't seem alien at all
Barney Carroll
@barneycarroll
Jan 12 15:08
Something that interests me is transient on the fly code transformations
James Forbes
@JAForbes
Jan 12 15:09
But in other contexts I'd try it for sure except I'm very satisfied with it, I love how things align now
Barney Carroll
@barneycarroll
Jan 12 15:09
In the same way git bash users are familiar with check-out-windows-line-breaks, check-in-unix-style
James Forbes
@JAForbes
Jan 12 15:09
like
const a =
  [ something
  , somethingElse
  , wowSoMuchSOmething
  ]
Yeah I'm interested in that too
and querying ast's to get work done. Like as if it's a database.
Barney Carroll
@barneycarroll
Jan 12 15:10
Too often we try to prosecute these things determinatively based on context, but with views it's … totally a view concern
James Forbes
@JAForbes
Jan 12 15:13
Yeah, I've picked up a lot of very view specific programming practices that I'd never do anywhere else, like we were saying the other day. In a view, nesting has practical use, where in data flow it's an obstruction it reduces clarity. That's fascinating to me. Because its all just data, what justifies these boundaries, and why? Is it purely context? Is it what our tooling expects or is it actually fundamental qualities of certain structures?
One thing I always scoffed at was alphabetising imports, but I had a realisation

that makes sense if you have more than a few imports because it let's you spot duplicates.

But then in node, duplicate imports do nothing, it's just cached. And in static langs... well again, it's static. It doesn't do anything.

So I'm left with, if we can't identify it's duplicated without alphabetizing, and duplicates have no practical effect on anything, what's the justification?

And how much effort is required in retaining that? And what if there's semantic use in grouping your imports in a different way in a particular file. Or what if import order has important because of cyclic deps.

Barney Carroll
@barneycarroll
Jan 12 15:17
This is what infuriates me about hard-and-fast linting rules for reference declaration formatting…
The contextual cognitive semantics are always more important than whatever perceived best practice
James Forbes
@JAForbes
Jan 12 15:18

There's all these things in programming. Like PEP8. That people get really passionate about. And I think that's fine, but be honest that it's aesthetics, don't intentionally inflate the importance of the aesthetic you prefer and say it helps "maintainability" or something.

Meanwhile there's practices that actually seem to solve problems. That's a different category. And it's hard to even identify the difference because the discourse is: my aesthetic makes code better!

Barney Carroll
@barneycarroll
Jan 12 15:19
If I'm declaring 2 variables, it barely matters. If I'm declaring 15, alphabetisation is the least of my worries. I need more contextual semantics to make sense of this, which is often cheaply determined by some vague on the spot subgrouping
James Forbes
@JAForbes
Jan 12 15:20
Every client I have has wildly different expectations about code style, and they get very passionate about things like tabs vs spaces. It's just so ridiculous. I mean whatever position you have on semicolons, at least it has an affect on the runtime. But tabs vs spaces! It's so ridiculous to have a position :D

alphabetisation is the least of my worries

Yeah exactly!

Barney Carroll
@barneycarroll
Jan 12 15:21
What's the significance of menuFactory in this code block? The same significance as everywhere else: m occurs halfway through the alphabet. menuFactory is an extremely halfway kind of reference, the code should respect that in a consistent manner.
I had tabs vs spaces with web reflection once, that was hilarious, luckily neither of us had firearms
James Forbes
@JAForbes
Jan 12 15:22
I really can't wait until we don't even type programs, its just so silly.
I used to like more than the other, I don't even remember which one it was now
My secret reason for my preference was that whatever language I liked did that
and so it changed, and then I probably realised how silly it is
do you have a link? :D
Barney Carroll
@barneycarroll
Jan 12 15:24
Regional law prevents me from sharing under Hate Speech legislation
James Forbes
@JAForbes
Jan 12 15:26
haha
Andrea Coiutti
@ACXgit
Jan 12 15:26
lol
Barney Carroll
@barneycarroll
Jan 12 15:28
He was saying 2 spaces, I was saying tab, it's specifically for indentation, the rest is exclusively personal aesthetics you can control entirely in your client
But he rejoined that since tab was an unconfigurable 8 spaces in SSH tunneling, client concerns were not as easily hand waved as all that
Barney Carroll
@barneycarroll
Jan 12 16:21
Delighted to find nested ternaries play extremely well with parenthesised comma operations: the latter allows you to circumvent the eslint rule forbidding the former 💪
Isiah Meadows
@isiahmeadows
Jan 12 16:23
@barneycarroll (re: trailing commas) Haskell allows an extra preceding comma similarly to how JS allows an extra trailing comma. Just for historical reasons (of course), we couldn't do the same - there's this (IMHO pointless) thing called array elision.
Just thought I'd point that out.
Barney Carroll
@barneycarroll
Jan 12 16:24
What's array elision?
Isiah Meadows
@isiahmeadows
Jan 12 16:24
var array = [1,,2], where 1 in array is false (It creates sparse arrays)
And yes, elisions can be at the start: var array = [,1]0 in array is false
ES3 baggage.
Barney Carroll
@barneycarroll
Jan 12 16:27
Aha thanks. Empty slot as opposed to false, surely?
Isiah Meadows
@isiahmeadows
Jan 12 16:27
No, it's literally empty. Try [,].hasOwnProperty(0) in a console.
Barney Carroll
@barneycarroll
Jan 12 16:28
Yes as opposed to no, surely?
OK I see those were in operations, I misread
Isiah Meadows
@isiahmeadows
Jan 12 16:29
:arrow_up:
Barney Carroll
@barneycarroll
Jan 12 16:29
Literal in operations
Isiah Meadows
@isiahmeadows
Jan 12 16:29
Yes.
Barney Carroll
@barneycarroll
Jan 12 16:30
Cool, didn't realise you could expose sparse arrays literally
Isiah Meadows
@isiahmeadows
Jan 12 16:31
It's a neat trick that doesn't make sense from a PL design standpoint.
When you have both trailing commas and array elisions, it complicates parsing quite a bit.
Oscar
@osban
Jan 12 16:33
@JAForbes maybe it also depends on the circumstances? This looks fine to me:
Isiah Meadows
@isiahmeadows
Jan 12 16:33
Also, it forces you to make the assumption literal arrays aren't always dense. (Sparse arrays are already the bane of engines' existence.)
@barneycarroll
Oscar
@osban
Jan 12 16:33
if (something) 'yay'
else if (someOtherThing) 'oh'
else if (someThirdThing) 'right'
else 'no way'
Isiah Meadows
@isiahmeadows
Jan 12 16:33
As for ternaries, I could make the argument that "if" is implicit (the condition is already distinct from each case), ? could be read as "then", and : could be read as "else". I don't have strong opinions on it (I'd rather if/else be an expression, and I'm not convinced it's impossible), but that's part of why I do ?/: first.
Barney Carroll
@barneycarroll
Jan 12 16:35
I agree @isiahmeadows, apart from the clunky verbosity of keywords I generally dislike statements, which make sub-expression parsing & refactoring harder
Isiah Meadows
@isiahmeadows
Jan 12 16:36
@barneycarroll Actually, it'd complicate expression parsing. You'd just have one loop instead of two.
Barney Carroll
@barneycarroll
Jan 12 16:37
@osban this would in principle work as an evaluated expression combined with do, but then we're relying on a lot more language features, in a similar space to special internal semantics of arrows-as-static-properties-of-classes
Isiah Meadows
@isiahmeadows
Jan 12 16:37
(BTW, I've dabbled a significant amount in JS parsing, as well as general PL language parsing. I'm not coming at this with no experience.)
Barney Carroll
@barneycarroll
Jan 12 16:37
I prefer sticking to the simpler operators, where far less could be happening
This is the thing that keeps me coming back to the value of nested ternaries: the argument against tends to be a feeling that the reader might misinterpret the operational logic, but a small amount of familiarisation reveals that you're actually drastically limiting the potential for ambiguous operational logic
@isiahmeadows heaven forbid anyone thought that
Oscar
@osban
Jan 12 16:40
@barneycarroll sorry, that went way over my head...could you explain it in a more simple way (to accommodate my simple brain)?
Barney Carroll
@barneycarroll
Jan 12 16:42
So the expression a ? b : c will evaluate to b or c
Whereas the statement if(a) b else c doesn't evaluate to anything
There's a proposal for a do statement which might change that
Oscar
@osban
Jan 12 16:45
@barneycarroll ah I see, thanks
But generally I try to avoid large conditions, and when they must be large I much prefer keeping the possibility space as small as possible
Large chains of if / else / else if can hide many more monsters than long ternaries
Isiah Meadows
@isiahmeadows
Jan 12 16:49
What merging the two grammars with my suggestion, statements and expressions (including do expressions), would do would be to simplify the grammar quite a bit at the expense of:
  • Slightly slower identifier handling for general expressions (more cases to check)
  • An extra single-token check for statements to read do as do ... while (block/object disambiguation is already required)

Large chains of if / else / else if can hide many more monsters than long ternaries

This is why if I have a non-trivial condition, I factor it out into a separate variable.

Barney Carroll
@barneycarroll
Jan 12 16:50
For example, in a long sequence of keyword-based conditional statements it's easy to miss one conditional tree ending and another beginning
The contents of an if can do anything, like throw, return, etc
Oscar
@osban
Jan 12 16:52
@barneycarroll yeah, I try to do that too. I will consider using ternaries more often :)
Barney Carroll
@barneycarroll
Jan 12 16:53
These kinds of pitfall are popularly acknowledged in reference to switch – inconsistent break makes the code very difficult to interpret
Arthur Clemens
@ArthurClemens
Jan 12 16:53
In other news, Polythene is mentioned in JavaScript Weekly of today
Barney Carroll
@barneycarroll
Jan 12 16:53
Ironically, extended if sequences are far worse in this regard, but somehow people are far more eager to use them instead of ternaries – which are far safer.
Oscar
@osban
Jan 12 16:54
@barneycarroll haha, @JAForbes has already convinced me to abandon switchand use a dict
Isiah Meadows
@isiahmeadows
Jan 12 16:54
@barneycarroll For complex logic, this rule helps discourage it.
@ArthurClemens Congrats! (I haven't looked at it yet, but I am a regular reader.)
Oscar
@osban
Jan 12 16:55
@ArthurClemens :clap:
Barney Carroll
@barneycarroll
Jan 12 16:55
@ArthurClemens yay! Recognition!
Arthur Clemens
@ArthurClemens
Jan 12 16:56
Don’t overdo it, it is just a link! But I’m still happy.
Barney Carroll
@barneycarroll
Jan 12 16:58
Hehe
TBH Javascript Weekly is the only JS news I read
Isiah Meadows
@isiahmeadows
Jan 12 17:02
@barneycarroll :arrow_up:
Barney Carroll
@barneycarroll
Jan 12 17:05

Missed this @isiahmeadows

This is why if I have a non-trivial condition, I factor it out into a separate variable.

That's golden advice
In my last job I encountered a codebase for a questionnaire that asked the user various questions and gave them advice. One function included 5000 lines of sequential conditional logic
Arthur Clemens
@ArthurClemens
Jan 12 17:08
I assume that questionnaire got a mind of its own
Barney Carroll
@barneycarroll
Jan 12 17:09
Pretty much. The powers that be thought it would be a terrible waste to abandon this 20,000 LoC project but I insisted the only rational way to proceed was to start from scratch based on a re-specification
Because the thing is with switches and if sequences, is you can't tell if an odd discrepancy is a mistake or not. return or a dangling else followed by an if look wrong, but maybe they're essential to the logic?
Trying to find bugs in code like that is impossible, because the line between bad style and accident is so blurred.
Isiah Meadows
@isiahmeadows
Jan 12 17:22
@barneycarroll Here's my thought: first thing to do: start splitting it into functions. Name things as you go along, as best as you can. Then you can start figuring out how the hell to actually make sense of any of it. (BTW, that's where my 0.2.x contributions came from: I had to pick apart a 200+ line function before I could fix any of the perf or behavioral issues.)
Barney Carroll
@barneycarroll
Jan 12 17:23
God yeah I remember that
The thing is, splitting into functions becomes difficult in the case of early returns.
The problem in the first place with these paradigms is that huge reams of liberal imperative code cannot a priori be procedurally reduced to simpler patterns
Isiah Meadows
@isiahmeadows
Jan 12 17:26
True. But you could still make some semblance of abstraction unless every other line has an implicit return. Also, booleans help.

The problem in the first place with these paradigms is that huge reams of liberal imperative code cannot a priori be procedurally reduced to simpler patterns

Very true.

I couldn't tell you how many times I wish JavaScript had a dedicated "reference" type that I could use, which helps a lot more than you might expect when abstracting imperative code.
Barney Carroll
@barneycarroll
Jan 12 17:28
But this is the thing, maintaining v0.2 was nightmarish. A rewrite was necessary.
Isiah Meadows
@isiahmeadows
Jan 12 17:38
:+1:
Barney Carroll
@barneycarroll
Jan 12 17:46
And I absolutely appreciate the untold effort you personally put into that, much of which is very difficult to qualify in hindsight because massive refactoring projects had to be abandoned.
It is worth stating that from my experience of having worked in a large variety of private development environments, these problems are generally far worse in closed source.
The difference between public / private is that the various failings of public projects are notionally universally visible, whereas closed source development champions its successes and conceals its failures.
The truth is that enterprise problems of this kind suck in far more dedicated labour and generally yield far worse results because of various corporate political concerns.
Barney Carroll
@barneycarroll
Jan 12 17:56
Which is one of the reasons that — regardless of the specifics — I am particularly cynical about eg AirBnB coding style being a thing people respect on principle. AirBnB deliver a lovely user experience, and they can certainly afford to hire great developers and treat them well — and pay them for dedicated work evangelising their products. Does that mean I should trust their open source offerings? No, not in the slightest.
React worked great for the eminently successful Facebook, as a library developed to help them write the embedded comments widget for third party sites, apparently. Angular worked great for building Google forms, so we're told. Does that mean those companies incredible financial success and corporate image will rub off on me when I use the same tools for squints at project proposal company X's new whitelabel inventory tracking software? No, if course not.
</totallyTangientialRant>
Isiah Meadows
@isiahmeadows
Jan 12 18:20

It is worth stating that from my experience of having worked in a large variety of private development environments, these problems are generally far worse in closed source.

From the little I've seen of various companies' less-open OSS projects, I would have to be inclined to agree.

React worked great for the eminently successful Facebook, as a library developed to help them write the embedded comments widget for third party sites, apparently. Angular worked great for building Google forms, so we're told. Does that mean those companies incredible financial success and corporate image will rub off on me when I use the same tools for squints at project proposal company X's new whitelabel inventory tracking software? No, if course not.

I take things very skeptically and pragmatically here. If it stands well on its own merits (e.g. Yarn), I'll definitely accept it. If it kind of sucks, but it is still usable (e.g. React), I'll be okay with using it, but I won't seek it out for my own projects. If it is just straight up ugly and fails to fulfill its core premise of existence (e.g. Angular), I will avoid it like the plague it is.

Also, some things work well in some aspects (Ember is well suited for data-centric CRUD applications, where your entire service all the way to how your end user uses it is stateful by necessity), but not in others (anything tree-based, including vdom-based, is terrible for non-hierarchial data).

Barney Carroll
@barneycarroll
Jan 12 18:27
These are excellent principles. The thing that continues to surprise me in my working life is the number of otherwise very sharp and judicious developers who are incapable of applying critical reasoning politically when it comes to third party software investment.
Patrik Johnson
@orbitbot
Jan 12 18:43
I'd guess it's not really viewed as problematic, or basically anything trendy is good for resumé padding anyways
Isiah Meadows
@isiahmeadows
Jan 12 18:46
@orbitbot More to the point, not enough people care until it bites them, then either it's their problem (and the project gets scrapped 99% of the time), or it's not their problem (and it's not a problem to them).
cavemansspa
@cavemansspa
Jan 12 18:54
i believe it's been discussed here before, but there's the issue of companies picking the "popular" frameworks because they can find developers to hire, and developers learn the popular frameworks so they can find companies that will hire them. irrespective of the technical merits of the framework.
Barney Carroll
@barneycarroll
Jan 12 18:55
A problem whose solutions are never considered seriously is essentially insoluble and therefore not a problem on a competitive political level. Which is why I'm especially dispirited that no-nested-ternary is advertised as a good thing and adopted on faith by sooooo many people.
@cavemansspa yes, it's good politics for a broken economy.
Condescension over consideration
Isiah Meadows
@isiahmeadows
Jan 12 18:57
@barneycarroll I'm actually for avoiding nested ternaries: it's a sign your logic is too complex. If it's really that complex, you should seriously consider breaking it up, either into separate statements or separate functions.
But yeah, I do agree companies should be deferring to the developers on what should and shouldn't be used for most things. For one, WhatsApp famously only needed 55 engineers to manage their 100M+ user base when they were bought by Facebook.
And they picked some of the more obscure technologies (Erlang + OpenBSD).
Patrik Johnson
@orbitbot
Jan 12 19:19
though, with a bit of hindsight, I don't know that we necessarily should expect any normal dev to have any particular clue about a domain they haven't already worked in for x amount of years
including tooling and eslint etc etc
Isiah Meadows
@isiahmeadows
Jan 12 19:21
Which adds to the list of reasons why you should let the devs choose the tech. They prefer React, you choose Angular, you've just delayed the project by a solid month minimum while they work on getting up to speed with using the framework, while they're trying to also write the app. (That's not counting other lost productivity issues.)
Patrik Johnson
@orbitbot
Jan 12 19:21
I wouldn't take it as a given that anyone has spent any amount of time really contemplating detail Y for any amount of time, unless they're explicitly tasked with it (and goes about without just accepting the mainstream of said domain) or has worked/lived in a culture which already has an opinion on detail Y, or if it's central to the actual domain of what the org is working on
I'm basically saying that devs also make uninformed choices. All the time
well, people in general :)
(guess that PR didn't get accepted yet) :P
Isiah Meadows
@isiahmeadows
Jan 12 19:24
True, and you could verify that by having them explain why they want it. You don't even need to always question the particular points - you just need to get them to fully explain it to themselves.
@orbitbot Which PR?
Patrik Johnson
@orbitbot
Jan 12 19:25
@porsager created a gitter PR that changes the emoji for :)from :) to :slighly_smiling_face:
... err, whatever the other one is.
:-)
... nope
Isiah Meadows
@isiahmeadows
Jan 12 19:25
But there are ways to ensure people actually understand what they're getting into, even if you don't know the details or even the particulars of the general field.
(Figuring out how on your own is more of a matter of basic psychology than it is actually knowing the field they're in.)
Patrik Johnson
@orbitbot
Jan 12 19:26
I guess you're talking about "people" and "you" as separate entities
any particular process you prefer?
Isiah Meadows
@isiahmeadows
Jan 12 19:32
It's somewhat situation-dependent, but it comes down to getting them to understand what they themselves are getting into, and making sure they aren't doing it blindly. I've done it myself when talking to people about projects I have little clue about. You get them to explain the nuances to you and try to get them to break it down enough you have at least a few hints as to what they're talking about, and they will often start coming up with ideas they weren't even thinking about or issues they had never even considered, even if you have no clue what they're even referring to. And if they find issues with what they were doing, quite frequently, you've just gotten them to embarrass themselves in front of you, which is a reward unto itself sometimes.
It's been said that teaching is one of the best ways to learn, and teaching is also the ultimate test of someone's knowledge. If they can't teach you something, they don't fully understand it themselves.
Patrik Johnson
@orbitbot
Jan 12 19:41
the teaching bit echoes true
Isiah Meadows
@isiahmeadows
Jan 12 19:44
It's one of those things that's mostly just common sense, though...
Taking a well-known fact and applying it. The only difference is that you're not applying it in where people normally associate it, but it's not that hard.
Barney Carroll
@barneycarroll
Jan 12 19:53
'Well-known facts' ;)
But you're right in principle
Isiah Meadows
@isiahmeadows
Jan 12 19:54
Okay, well-known in some circles. But you get my point. :smile: