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.

Making invisible glue code first-class

91 pointsby pcr910303almost 4 years ago

10 comments

codeismathalmost 4 years ago
I recently watched a video [0] that contrasted all of the OO Design Patterns with Functional Programming equivalents. After reading about how this author wants to make &quot;glue&quot; code &quot;first class&quot; and how the Unix pipe operator is an example of single-character-glue-code, my thoughts immediately went to the aforementioned video presentation. Perhaps my &quot;glue code&quot; is simply gold-old &quot;function composition&quot;?<p>[0] Scott Wlaschin &quot;Functional programming design patterns&quot; <a href="https:&#x2F;&#x2F;vimeo.com&#x2F;113588389" rel="nofollow">https:&#x2F;&#x2F;vimeo.com&#x2F;113588389</a><p>[Edit] Spoiler alert: each of the design patterns reviewed and contrasted in the video I mentioned seemed to &quot;disappear&quot; in FP since the equivalent is simply to use functions and&#x2F;or function composition. Recently transitioning from C# to F# for my .NET Core projects, I felt the &quot;glue code&quot; the author mentions disappear in a similar manner with greatly-reduced code bloat.
评论 #27490349 未加载
评论 #27489345 未加载
评论 #27499990 未加载
评论 #27488548 未加载
crazygringoalmost 4 years ago
This is a really excellent topic to bring up -- the fact that glue code grows essentially quadratically.<p>Has it been a topic of exploration much in computer science? Any literature?<p>After all, sometimes it feels like <i>most</i> of the programming you wind up doing is glue code.<p>On the one hand, it feels like the kind of thing that there should be better tools for at least writing it <i>declaratively</i>, and let the computer turn it into code.<p>But on the other hand, it feels like a lot of that already <i>is</i> taken care of. E.g. CSS is essentially declarative glue code for what would otherwise be a huge number of painting and layout lines of code.<p>And most of the glue code I myself wind up writing winds up being written specifically to handle various constraints around memory, disk space, etc -- e.g. how to import a protobuf that changes every 30 seconds and convert it to 10,000 rows in a live database in a way that&#x27;s performant -- and so isn&#x27;t as amenable to something simple.<p>But I do still wonder if there&#x27;s more opportunity here for more declarative coding when it comes to &quot;glue&quot;.
评论 #27489341 未加载
评论 #27487637 未加载
l0b0almost 4 years ago
Treating shell scripts as first class has taken me on a bit of a journey over the last decade:<p>- Learned from shunit2 that it&#x27;s possible to write solid shell scripts, and that writing test code in shell scripts is hard to learn but doable. Bonus: I&#x27;d rather write the test script in a more easily debuggable language, such as Python.<p>- Bash has many more surprises in store for you than any other mainstream language. How $IFS affects things, how looping over files is either completely trivial (`for file in *`) or damn near impossible (`while IFS= read -d &#x27;&#x27; -r -u 3; do …; done 3&lt; &lt;(find … -exec printf &#x27;%s\0&#x27;)`) based on the pattern you want to match, exit codes of arithmetic assignments, all the tricks to deal with not having exceptions, how `ls` is unsuitable for scripting despite being ubiquitous, locales, variable flags, and so on.<p>- `shellcheck` is fantastic, especially for including URLs to more information about each warning.<p>- Greg&#x27;s Wiki[0], despite being hard to find in search engines, is the best place by far for learning about Bash.<p>- Writing a shell script to do some fast, asynchronous processing is maybe 30-100 times faster than writing the same in Python, but getting the nitty-gritty details right is about 30-100 times harder as well.<p>[0] <a href="https:&#x2F;&#x2F;mywiki.wooledge.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;mywiki.wooledge.org&#x2F;</a>
awolfalmost 4 years ago
One patten I&#x27;ve seen to address this is to define a &quot;plugin architecture&quot; where disparate components are integrated into the main system via fixed &quot;sockets&quot;. The sockets themselves are generic as is the glue code that attaches plugin and socket.<p>This does create a lot of boiler plate, but that boiler plate is predictable and uninteresting, and a good candidate for code generation.
评论 #27487836 未加载
rocquaalmost 4 years ago
Isomorphisms.<p>They let us think about things very easily, and express ideas very cleanly. When I Think about a system, I treat isomorphic things as almost exactly the same.<p>But when actually writing code, I need to fully spell out the isomorphism. That is glue code.So the code becomes my clear ideas, with awkward glue in between.<p>My dream is a compiler that knows these isomorphisms, and automatically implements them with decent (perhaps guided by me) optimization.<p>This way, the idea in my head and the code in my editor start looking like eachother a whole lot more.
评论 #27487972 未加载
fierroalmost 4 years ago
I&#x27;m not understanding the importance of distinguishing glue code from non glue code. It&#x27;s still work that needs to be done whether it&#x27;s &quot;first class&quot; or not. That difference boils down to who writes it, not the fact that it is present in the code base (as measured by LOC, which the author measures and attributes the cause of high LOC to glue code)
fierroalmost 4 years ago
I read this article but am having a hard time understanding the point in concrete terms. What does it mean to make invisible glue code first class? How would reduce the #LOC, which is something the author mentioned many times?
评论 #27495394 未加载
______-almost 4 years ago
It&#x27;s worth researching the demoscene[0] and how demos that looked <i>very complex</i> were made with as few lines of code as possible. Every byte was accounted for and nothing went to waste.<p>This is a common thing in games and Super Mario even re-used the cloud sprite for the bushes[1]<p>Now we have to deal with gargantuan Electron apps that hog your PC&#x27;s resources for housing what essentially is a lightweight webapp.<p>[0] <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Demoscene" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Demoscene</a><p>[1] <a href="https:&#x2F;&#x2F;www.todayifoundout.com&#x2F;index.php&#x2F;2010&#x2F;01&#x2F;the-clouds-and-bushes-in-super-mario-bros-are-the-same&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.todayifoundout.com&#x2F;index.php&#x2F;2010&#x2F;01&#x2F;the-clouds-...</a>
评论 #27499619 未加载
fouricalmost 4 years ago
I posted this to Lobste.rs when this story hit there and I&#x27;ll post it again here:<p>&gt; The pipe is one-character glue: “|”.<p>I think that this is mistaken. Pipe makes it easy to connect the output of one program to the input of another, but that is not the same as “gluing” them - you have to do text processing to actually extract the fields of data out of the output from one command and convert it into the right format for input to another.<p>This is why you see tr, cut, sed, awk, perl, grep, and more throughout any non-trivial shell script (and even in many trivial ones) - because very, very few programs actually speak “plain text” (that is, fully unstructured text), and instead speak an ad-hoc, poorly-documented, implementation-specific, brittle semi-structured-text language which is usually different than the other programs you want them to talk to. Those text-processing programs are the Unix glue code.<p>The explicit naming of “glue code” is brilliant and important - but the Unix model, if anything, increases the amount of glue code, not deceases it. (and not only because of the foolish design decision to make everything “plain” text - the “do one thing” philosophy means that you have to use more commands&#x2F;programs (which are equivalent to functions in a program) to implement a given set of features, which increases the amount of glue code you have to use - gives you a larger n, which is really undesirable if your glue code scales as n^2)
评论 #27487787 未加载
评论 #27490371 未加载
评论 #27488543 未加载
TechBro8615almost 4 years ago
I don’t understand why “master” is problematic but “first class” is okay.
评论 #27489410 未加载
评论 #27490063 未加载