TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Application-as-a-Function Thinking

83 pointsby kodroidover 2 years ago

11 comments

AugustoCASover 2 years ago
I couple of years ago I was lucky to use http4k, a server as a function web library for Kotlin. It was such a wonderful change compared to every other technologies available in both Java and Kotlin. It&#x27;s simple.<p>Testing becomes so much easier too, as one can instantiate a the whole web routing aspect, without having to bind it to a port and having to send real http requests.<p>If strongly suggest people to take a look at it. It&#x27;s not perfect, but it&#x27;s a lot simpler than other frameworks and libraries. And it&#x27;s a shift in some of the current mentality of using heavy frameworks (such as spring boot) which blow up anyone&#x27;s cognitive load.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;http4k&#x2F;http4k" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;http4k&#x2F;http4k</a>
评论 #33222565 未加载
评论 #33222671 未加载
评论 #33224581 未加载
评论 #33223065 未加载
stevanover 2 years ago
I like to think of it as &quot;application-as-functional-specification&quot;.<p>A functional specification for a stateful system is a function from a list of all inputs to an output, i.e. `fun spec(inputs: List(Input)): Output`.<p>This kind of specification doesn&#x27;t need to specify `State` at all, as we can simply refer to previous inputs. E.g. imagine a counter system with the inputs `Increment`, `Reset`, and `Get`. The functional spec for `Get` is &quot;find the latest reset and then count the number of `Increment`s since then&quot;.<p>I think this is neat, because if you are developing the functional spec with a domain expert that doesn&#x27;t know programming you don&#x27;t wanna bother them with, for them, unnecessary bookkeeping details.<p>From this spec you can then figure out what `State` needs to be, but this can be done as a separate step not involving the domain expert but rather other developers.<p>I learnt this from the Cleanroom software engineering people, they call the spec without `State` a &quot;black box spec&quot;, while the one with `State` is called a &quot;state box spec&quot;. (There&#x27;s also a third step called &quot;clear box spec&quot; where they break down the &quot;state box spec&quot; into functions.)<p>I&#x27;ve been playing around with the idea of designing a specification language that lets you write &quot;black box specs&quot; together with some basic sanity checks of those specs, because I think there&#x27;s a lot of value in this sort of structure.<p>For example even if your application doesn&#x27;t follow the &quot;application-as-function&quot; pattern, you can still use your &quot;state box spec&quot; as an oracle when doing property-based testing of your application.
评论 #33223059 未加载
评论 #33222433 未加载
iddanover 2 years ago
This is basically introducing Elm (a.k.a the inspiration for Redux) to Android. At least for me this model doesn’t work. Application is all about transitions of state, yes, but <i>in context</i>. That’s why React’s model of managing multiple state points in different levels of the application tree makes so much more sense to me
评论 #33226338 未加载
评论 #33223185 未加载
评论 #33222388 未加载
_dain_over 2 years ago
How well does this approach scale for systems where the state is inherently large and complex? I write code that controls industrial machinery. There&#x27;s just <i>loads</i> of different knobs and settings and modes that I can control with code, and a single production or test run will involve several heterogeneous machines, so the total state space is the cartesian product of all of those (not to mention the state of the physical widget they&#x27;re all acting on, which we can only know imperfectly). I&#x27;m trying to imagine writing a data structure to represent all the different configurations the system can exist in, and it would need hundreds of different arguments just to instantiate it. The function to compute one state to another would be enormous and inscrutable. How do you deal with that?
评论 #33226576 未加载
mpweiherover 2 years ago
No.<p>Applications are <i>not</i> functions.<p>How many applications that you use on a daily basis work as follows:<p>1. You prepare some parameters<p>2. You start the application with those parameters.<p>3. The application goes away and thinks for a bit.<p>4. The application returns with a result and then exits.<p>Trying to make actual applications and system fit into the function (or procedure) mold is, IMHO, one of the biggest obstacles to software simplicity, as there is a fundamental architectural mismatch here.<p>In the early days of computing, a lot of programs actually did work this way, which is why DSLs for algorithms (ALGOL) were appropriate, and probably where the idea originated that they are actually general purpose languages. Which they are not.
评论 #33223937 未加载
评论 #33223331 未加载
评论 #33224335 未加载
评论 #33223288 未加载
评论 #33223945 未加载
评论 #33225428 未加载
评论 #33223352 未加载
评论 #33223310 未加载
brapover 2 years ago
Very cool to see this! I&#x27;ve actually given this some thought a few years back when attempting to create (yet another) JS framework, and came up with something very similar to this! For me the difficult part was where the side effects fit in and how they&#x27;re processed, what you call &quot;commands&quot; and &quot;command handler&quot;. I didn&#x27;t find an elegant solution to this and abandoned the idea early on, sparing the JS community.
评论 #33226357 未加载
monocularvisionover 2 years ago
Love this, thanks for sharing. This is fundamentally how our iOS application is modeled. We were highly inspired by Bernhardt’s talk and the Elm Architecture.<p>It has lead to a very modular and maintainable app that has been very easy to test without ridiculous mocking you usually see when needing to interact with object-oriented &#x2F; imperative frameworks like Cocoa Touch.
评论 #33237706 未加载
raydiatianover 2 years ago
&gt; “Application as a Function”<p>Forgive me if I’m oversimplifying, but isn’t this just “stateless servers” and “router-service separation” at its core? Maybe this isn’t targeted for the API crowd, but anybody who has spent even a few months learning modern client-server programming understands this, and web dev is pretty common these days…
评论 #33222342 未加载
评论 #33226434 未加载
评论 #33224814 未加载
12thwonderover 2 years ago
it seems like less sophisticated version of reactive paradigm to me, am I wrong?
评论 #33222172 未加载
评论 #33226514 未加载
wizofausover 2 years ago
Nitpick, but you have an unwanted apostrophe in your first sentence...
评论 #33237717 未加载
erwinhover 2 years ago
In a way for me smart contract blockchains are a good example of developers focussing on creating very efficient functional building blocks. A smart contract has &#x27;functional&#x27; aspects in that it produces operations that update the state&#x2F;storage. Developers are incentivised to think about direct cost due to gas&#x2F;storage fees. Chain-level transaction standards create a base-level of interoperability.<p>All of this being on-chain basically gives &#x27;event logging&#x27; out of the box so all functions (i.e. contracts) on a chain can be monitored by any developer involved.<p>(Building this part myself: <a href="https:&#x2F;&#x2F;thestackreport.xyz&#x2F;dashboards&#x2F;tezos" rel="nofollow">https:&#x2F;&#x2F;thestackreport.xyz&#x2F;dashboards&#x2F;tezos</a>)
评论 #33223721 未加载
评论 #33223455 未加载