r/javascript • • Apr 14 '23

AskJS [AskJS] Frameworkless, functional javascript discord/matrix community?

I created a community for those web developers who aren't satisfied with the state of the industry piling frameworks over frameworks to produce simple http servers, document layouts and event systems (and feel like doing more than just complaining about it, not as if the criticism alone wasn't valuable). It's tiring that all "javascript" discussion is about implementation details of NextJS/webpack/React/Angular/Vue, as if they were the platforms we are developing against and not just libraries with oversized scopes, and i have to talk with senior programmers who don't even know what XML namespaces are, or never seen flatMap before because they never had to implement more complicated algorythms than setting state and passing component properties.

If you would like to talk about optimal solutions in practice, in the abstract, or even in pseudocode, for routing, server-side rendering, stylesheet/script compilation, AST parsing/serialization, persistence/IO, continuation, hydration, state management, general traversal algorythms, function composition, god forbid "category theory", etc., then you are welcome to join fellow curious minds in our discord/matrix community (discord has more thematic channels, only the main one is bridged with matrix):

https://discord.gg/GvSxsZ3d35
https://matrix.to/#/!ipeUUPpfQbqxqMxDZD:matrix.org?via=matrix.org&via=t2bot.io

the fact that we've had a peak member count of 20 over 2 years i think speaks of a dreadful state of the mainstream web development mindset, so it should motivate you to join even more. Hope to see you there!

Javascript isn't the problem that needs to be solved, but the tool to solve the problem of html and css.

6 Upvotes

24 comments sorted by

View all comments

Show parent comments

2

u/martingronlund Jul 08 '23

I'm concerned about e.g. partial application creating new functions, e.g.

const say = (print) => (lang) => (word) => print(lang[word]); say(console.log)({ hi: "woof" })("hi");

When you start going tagless final and everything is piped monadic expressions including state, reader, task, either and you have to lift functions to fit context, it's a bunch of extra allocations and dynamic function invoctions everywhere. And as you said, we don't have tail call optimization either. I can't help feel like it's the wrong language for doing functional programming at large.

These days I lean towards solid data type definitions and write mostly inlined procedural code. Only when I can't inline something into happening only in one single place do I create indirection. I find this creates very straightforward easy to maintain code, but yeah I draw a lot of inspiration from declarative functional programming once I need a level of indirection, and especially when I need an abstraction.

1

u/miracleranger Jul 08 '23 edited Jul 08 '23

that sounds perfectly reasonable. i might only perceive the inspiration gained from functional programming more useful. i don't refrain from "inlined prodecural" statements either, only find abstraction more reliable. your example of atomic "state, reader, task, either" monads seem jarringly obscure indeed when used directly at higher abstraction levels, and the language used by functional libraries do appear to contain such vocabulary. this is the reason i have been implementing my own abstractions instead, and in the process of composition i organize parts such that they make sense. in practice the difference simply becomes a declaration of verbs more often than nouns. loadcontent=compose(fetch, parse, either(text, chart, media), container, insert);loadcontent(url, {method:"get"}) - such an action can read much like plain english, and the more obscure core monadic functors of IO/state/identity/promise etc remain composed in the combinators of these higher abstraction level. (an instance of Either being an exception, but it seems the appropriate level of abstraction there).

regarding the obscurity of partial application, i am actually on your side and am very much against excessive partial application. functions that take a function as argument but don't return one back (operate with the argument instead of composing it) are the definition of inversion of control, and i think they should be distinguished much more from higher order functions that do return functions, and don't mix data with behavior in their arguments (combinators/closures). a compose() function for example requires to preserve the functions to be composed in the lexical scope of its closure, but that's very different from partial application of a single function with multiple arguments. in fact i don't consider functions with a (private) lexical scope pure anymore. the concept that made this popular is currying, which is a technical necessity in functional languages where multiple arguments are only syntactic sugar for it. in javascript a variadic composition is not such a big deal, and currying has much smaller utility.

so in my view, the combination/composition of functions and eventual transmission of state across the resulting boundaries does not incur unnecessary complexity when done right, only procedural clarity.

2

u/martingronlund Jul 08 '23 edited Jul 08 '23

Right, nice comment about higher order functions vs inversion of control. I think it boils down to how much overhead we dare swallow before we feel our ivory towers crumble. E.g. even an Either means we have to allocate an object and put a tag on it (at least this is a common encoding) just because we don't want to deal with untyped errors (in case of TypeScript), unwound call stacks, and try/catch. So while we gain another way of expressing ourselves, I frequently feel it's not worth it. Of course, it depends, but I've mostly turned away from it.

Btw one nice thing I started doing was making types like PAF<X, Args extends readonly unknown[]> = Promise<ReadonlyArray<(...args: Args) => X>> etc (of course using intermediate P, A and F for the above definition. I found this very expressive.

1

u/miracleranger Jul 08 '23 edited Jul 08 '23

lol it's those generic type definitions that give me the heebie jeebies instead. the abbreviations and shorthands can especially kill me. is that a promise returning multiple functions of the same signature and return type? (why?) i take it PAF is for partially applied function? and what's intermediate about them lol? but let me show you my implementation of Either in return (wondering if you would spot your concerns about "tagging"/error specification/"unwound stacks" verified in it. nb. it's not my prettiest combinator, the internal proceed() function is a bit obscure in this form. especially w/o syntax highlighting. combine(compose(drop(1,0,terms),infer),drop(0,1)) is just like (term,i)=>[terms[i], term], but nvm):

 export function either(functor,...functors)  
{// alternative inference until assertive term found. (errors cumulate in context)  
 if(this===undefined)  
 return describe(function(...context)  
{if(this!==undefined)context.unshift(this);  
 return either.call(provide(context,true),functor,...functors);  
}  
,either,...arguments);  
 let context=collect(this);  
 if(functor===undefined)  
 return context.shift();  
 let attempt=compose(provide,functor,proceed);  
 if(!functors.length)  
 return attempt(context);  
 try  
{let scope=attempt(context);  
 return scope instanceof Promise  
?scope.catch(fail=>compose.call(context,provide,fail,proceed))  
:scope;  
}catch(fail){return compose.call(context,provide,fail,proceed);}  
 function proceed(...terms)  
{let invalid=!terms.some(term=>assert(term));  
 if(!invalid)  
 invalid=context.length&&
 context.every(compose  
(combine(compose(drop(1,0,terms),tether(infer)),drop(0,1))  
,Object.is  
));
 if(!invalid)  
 invalid=terms.every(term=>term instanceof Error);  
 return invalid
?either.call(provide(terms),...functors)  
:provide(terms);  
};  
};  

i think your observations are valuable though, we have some static typing oriented people in the group to check our sanity from time to time already, you are welcome to join that opposition party. :D

→ More replies (0)