<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Marius Ibsen on Medium]]></title>
        <description><![CDATA[Stories by Marius Ibsen on Medium]]></description>
        <link>https://medium.com/@marius-ibsen?source=rss-830a2ef44966------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*JpC_Y1TrlnMtynzC4iPzYg.png</url>
            <title>Stories by Marius Ibsen on Medium</title>
            <link>https://medium.com/@marius-ibsen?source=rss-830a2ef44966------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 06:40:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@marius-ibsen/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Erfaringer fra arbeid i tverrfaglige team]]></title>
            <link>https://medium.com/dfind-consulting/erfaringer-fra-arbeid-i-tverrfaglige-team-3243f38daab8?source=rss-830a2ef44966------2</link>
            <guid isPermaLink="false">https://medium.com/p/3243f38daab8</guid>
            <category><![CDATA[tverrfaglighet]]></category>
            <category><![CDATA[teamwork]]></category>
            <category><![CDATA[smidig-utvikling]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[systemutvikling]]></category>
            <dc:creator><![CDATA[Marius Ibsen]]></dc:creator>
            <pubDate>Mon, 30 Jan 2023 19:10:57 GMT</pubDate>
            <atom:updated>2023-03-10T11:19:58.070Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EgsCn4V61NW3AYRs" /><figcaption>Photo by <a href="https://unsplash.com/@marvelous?utm_source=medium&amp;utm_medium=referral">Marvin Meyer</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I hele min karriere har jeg vært opptatt av å skape et nært bånd mellom design og utvikling. I team jobber man ofte mot de samme målene, og er avhengig av hverandre for å nå dem. Ved å ha et åpent sinn og transparent arbeidsmiljø, vil man kunne lære en hel del, om og av andre, som nesten alltid vil komme til nytte. I min tid som konsulent har jeg opplevd og blitt kjent med mange ulike kunder, prosesser, team og mennesker. Om det er noe viktig jeg har lært, så er det at samarbeid på tvers av fag, og tett kommunikasjon, er helt nødvendig når man jobber i tverrfaglige team.</p><p>Men hva syntes jeg har fungert bra, og hva har fungert mindre bra? Og hva må til for at et team skal føle at det er på bølgelengde? Noen tanker rundt disse spørsmålene, og egne erfaringer, skriver jeg om i innlegget. Innholdet er like relevant for designere og utviklere, som ledere, forretning- og domeneekspeter.</p><h3>Transparens og åpenhet</h3><p>Et team som er transparent, er et team som kommuniserer åpent og ærlig om arbeidet og prosessene de har. Når man vet hva alle de andre i teamet ditt jobber med og hvilket ansvar de har, og samtidig vet at alle de andre har motivasjonen for å ville levere like bra som deg, og du vet hvem du kan snakke med om ulike problemstillinger, da vet du at teamet er på samme bølgelengde.</p><h4>Èn av ni løsninger</h4><p>I et møte hos en tidligere kunde ble jeg plutselig overrasket. Det jeg ble vitne til da, var to avdelinger som knapt kommuniserte med hverandre. La oss kalle dem for avdeling <strong>A</strong> og <strong>B </strong>— begge avdelingene var eid av samme selskap, <strong>A</strong> var bruker og <strong>B</strong> jobbet med utvikling. Avdeling <strong>A</strong> holdt et innlegg for avdeling <strong>B</strong> om hvordan de jobbet i sin avdelingen, og hvilke verktøy de brukte. De brukte <em>èn av ni</em> verktøy som avdeling <strong>B</strong> hadde laget for dem. De åtte gjenværende verktøyene løste ikke lengre de utfordringene som avdeling <strong>A</strong> hadde. Avdeling <strong>A</strong> forklarte hva som var problemet med de åtte verktøyene og hadde sjeldent noe positivt å si om dem. Den niende løsningene ble derimot sett på som det eneste brukbare, som fra Avdeling <strong>B</strong> sin side var et utdatert, usikkert og et dårlig lagd system. Uten å ha kommunisert utfordringene tidligere, kjøpte avdeling <strong>A</strong> andre verktøy og løsninger, og la til side de som ikke ble brukt, uten å si noe til Avdeling <strong>B</strong>. Vel uvitende jobbet avdeling <strong>B</strong> med optimalisering og forbedring, i god tro om at det de hadde skapt ble brukt. Grunnen til at kun èn av ni løsninger ble brukt, var i hovedsak mangelen på kommunikasjon mellom avdelingene. Ingen av partene var åpne om systemenes tilstand eller tok initiativ til å diskutere fremtidige behov og utfordringer. Ingen av partene var heller så interessert i hva den andre parten gjorde eller jobbet med, enda de satt vegg i vegg med hverandre.</p><p>Selv om historien over ikke handlet om det tverrfaglige teamet, er poenget det samme. Dersom man unngår å holde hverandre informert om utfordringer, kan lignende situasjoner oppstå. Man bør ikke kommeet punkt hvor man bare leter etter feil, før man forsøker å kommunisere eller løse de utfordringene man allerede har.</p><h4>Synliggjøring</h4><p>Åpenhet kommer tydelig frem når man synliggjør hvem som er ansvarlig for hva. Den personen som starter med en oppgave, er sannsynligvis den mest kompetente til å løse den i starten — mens andre kan bli mer kompetente på sikt. Synliggjøring av kompetanse og ansvar gjør at teamet blir bedre på å delegere arbeid og teammedlemmene vet hvem man kan spørre om hjelp for ulike problemstillinger. Samtidig bidrar synliggjøring til at informasjon ikke holdes skjult, men det er heller en strøm av ressurser og ideer som flyter mellom medlemmene. Synliggjøring er med på å skape tillit i teamet og styrker hvordan man samarbeider i sin helhet.</p><h4>Oppsummering: Transparens og åpenhet</h4><p><em>Jeg tror at team som er transparente har mindre utfordringer og at problemer løses raskere. Grunnen kan være at i transparente team, vil man jevnlig snakke om utfordringer, feil man har gjort og bekymringer. Medlemmene kjenner hverandres styrker og svakheter. Strømmen av informasjonen som flyter rundt i teamet gjør det tydelig hvem som har ulikt ansvar, oppgaver og kompetanse. Teammedlemmene har stor tillit til hverandre. De er ikke redd for å dele, få tilbakemeldinger eller motta kritikk, fordi teamet i utgangspunktet deler med hverandre. Dersom vi tør å snakke om feilene vi gjør, vil vi unngå at andre gjør dem også. Vi må godta at andre kan gjøre feil, og gi dem ros når de deler erfaringene med oss.</em></p><h3>Kunnskapsdeling</h3><p>Kunnskap er ferskvare, mens erfaring får man jo mer man anvender kunnskap. Når man deler kunnskap, bidrar man til at andre kan utforske den samme kunnskapen og bygge mer erfaring. Deling er en kritisk forutsetning for personlig og andre sin utvikling. Noen ganger har vi behov for å få andres perspektiver, gjennom tilbakemeldinger, innspill og konstruktiv kritikk for å utvikle oss.</p><h4>Deling mellom designere og utviklere</h4><p>Det viktigste et tverrfaglig team gjør for å holde hverandre oppdatert, er å dele kunnskap. Team som jevnlig deler kunnskap vil kunne diskutere kompleksitet i mye større grad, på tvers av fagområder, enn team som ikke gjør det.</p><p>La oss ta for oss noen fordeler som utviklere og designere kan få ut av å dele kunnskap: Utviklere kan få bedre innsikt i hvordan designere <em>arbeider</em> og <em>verktøyene</em> de bruker. Man vil oppdage feil og mangler lettere. Man får bedre forståelse for informasjonsarkitektur, brukertesting, universell utforming og kontraster, for å nevne noe. Dette gjør det mulig for utviklere å ta egne avgjørelser og gjøre endringer i grensesnittet uten å være avhengig av en designer til enhver tid. Designere kan få bedre innsikt i hvordan <em>komponentene (</em>samspillet mellom koden og designet) oppfører seg i brukergrensesnittet. Skisser og prototyper kan utvikles med dypere teknisk innsikt når man skal lage nye eller videreutvikle eksisterende løsninger. Designeren blir mer bevisst på hvordan data prosesseres og flyter mellom systemene — fra backend via frontend til sluttbrukeren — og kan sammenligne kode og design.</p><p>Jo mer designere og utviklere vet om hverandres fagområder, desto bedre vil man kunne diskutere forandringer i utseende, tekniske utfordringer, prioriteringer, ytelse og testing m.m. Det vil være enklere å holde kode, design og dokumentasjon synkronisert. Designsystemer kan være svært nyttig til dokumentering, og er et fint verktøy for å samle, synkronisere, strukturere og organisere informasjon i èn felles plattform (en såkalt «<em>single source of truth»)</em>. Designere og utviklere som er synkroniserte tar bedre avgjørelser, alene og i fellesskap.</p><h4>Oppsummering: Kunnskapsdeling</h4><p><em>En ting jeg husker spesielt godt, fra et tidligere prosjekt, var da jeg og en designer gjorde par-programmering og par-design for å dele kunnskap. De gangene vi leste kode, forklarte jeg hvordan koden og elementene i grensesnittet — designet — hang sammen. Andre ganger satt vi i Figma og diskuterte hvilke tekniske utfordringer vi måtte tenke på når designet skulle utformes. Designeren inviterte meg stadig med på brukertesting for å observere hvordan brukerne opplevde å bruke applikasjonen i den stegvise utviklingen over seks uker. Det viste seg å ha stor verdi for løsningene vi lagde i ettertid. Personlig har det også vært en svært nyttig erfaring for løsninger jeg har bidratt med å lage i andre prosjekter. Når man lærer bort trenger det ikke alltid være noe nyttig, det viktigste er at man får noe ut av læringen. Lær bort det du vet kan være nyttig for andre. Det finnes utallige måter å dele kunnskap på og det kan skje i mange ulike forum. Whiteboard med notislapper, verktøy som Trello, Figma eller discussions i Github er noen eksempler.</em></p><h3>Frihet og eierskap</h3><p>I tiden vi lever i nå, hvor endringer skjer utrolig raskt, er bedrifter helt avhengig av å fornye seg for å henge med. Kreative prosesser, eierskap og frihet under ansvar er derfor nødvendig for at vi skal lykkes med å skape nye ideer og nyttige resultater.</p><h4>Frihet under ansvar</h4><p>Selskapene som fanger interessen til dagens designere og utviklere, er de som har og gir stor frihetsfølelse. Det er også de selskapene som gir rom for egne perspektiver, der det er høyt under taket og lite byråkratisk ledelsesstruktur. Når man hele tiden blir fortalt hva man kan gjøre og hva man ikke kan gjøre, er det vanskelig å kunne være kreativ og bidra med sine beste ideer. Og, når man har fagkompetente mennesker som jobber for seg, er det snodig når en høyt oppe i systemet skal ta tekniske valg fordi de mener de har <em>en god magefølelse</em>. Å gi de ansatte større frihet til å velge selv, når de skal jobbe, hvordan og hvor de skal jobbe — om de vil delta på kontoret eller i møter — vil det mest sannsynlig resultere i lykkeligere ansatte. Det å stole på sine ansatte, og vite at de har kompetansen som trengs, er like viktig da de jo faktisk er profesjonelle på det de gjør. Der teamene har <em>frihet under ansvar,</em> kommer også lojalitet, produktivitet, fleksibilitet og effektivitet som et naturlig resultat.</p><h4>Eierskap</h4><p>At team tar eierskap for det man skaper, har sterk innvirkning på kvaliteten og arbeidsinnsatsen for sluttproduktet. For at teamet skal få følelsen av eierskap, må selskapene tørre å gi team og medlemmene <em>ansvar. </em>Ansvar betyr å gi teamet selvstendighet til å <em>eie</em> produktet ved å bestemme egne prosesser, metodikk, leveranser og teknologi. Med eierskap blir teamene mer selvdrevne og eksperter innenfor sitt domenet. Utviklerne og designerne kan fokusere på færre prosjekter, og de slipper å sjonglere mellom mange ulike domener, kontekster, prosesser og avhengigheter (møter, planlegging, standups) som ikke har noe med hverandre å gjøre. Eierskap gir mer trygghet, og dypere forståelse for det man jobber med, fordi man kan fokusere og bli ekspert på mindre deler av et prosjekt, domene, brukergruppe eller produkt.</p><h4>Oppsummering: Frihet og eierskap</h4><p><em>Jeg jobbet en gang i et team hvor en rekke utviklere og designere hadde fullt eierskap til flere løsninger innenfor et bestemt domene. Dersom en avhengighet utenfor domenet måtte løses, ble et annet team koblet på for å løse avhengigheten i det respektive domenet — fordi det var deres ansvarsområdet og ekspertområde. Jeg jobbet også i et annet team for ikke så lenge siden — der jeg kom helt fersk inn i domenet og selskapet –, hvor alle utviklerne kunne plukke utviklingsoppgaver fra mange ulike domener. Det var ikke så nøye hvem som gjorde hva, men oppgavene skulle løses. Utfordringen med å jobbe på denne måten, var at ingen fikk spesiell kompetanse på noen av domenene. Samtidig kunne du jobbe med enten SvelteJS, NextJS, NodeJS eller ren ReactJS, CSS, SCSS, CSS Modules eller StyledComponents. Personlig har jeg hatt en god opplevelse når det kommer til Frihet under ansvar. Men jeg tror at de teamene som har ansvar for få prosjekter, har lettere for å ta et større eierskap fordi de kan gå i dybden og konsentrere seg om færre ting. For mye eierskap kan gjør at man ikke kjenner godt nok til et domene. Dersom man er innom mange oppgaver og prosesser samtidig i ulike prosjekter, kan delegering av arbeid og ansvar fort føre til at man får mindre eierskap og oversikt for de enkelte prosjektene.</em></p><h3>Individuell og kreativ tenking</h3><p>Mange utviklingsteam jobber etter <em>smidige prosesser</em> som Scrum eller Lean. I smidige prosesser samles gjerne teamet en gang i blant for å snakke om ideer, progresjon, mål, oppgaver, ansvar og trivsel. Under samlingene, er målet som regel å arbeide og tenke som <em>et</em> lag. Men, det kan også handle om å finne roller og styrker i teamet eller meningen med hvorfor du og teamet eksisterer.</p><h4>Retrospektiv</h4><p>Retrospektiv er en ganske vanlig teknikk som benyttes i smidige prosesser. Teamet reflekterer sammen om hva som har fungert bra, og hva man kan forbedre i utviklingssyklusen. Dette er ofte kalt sprinter. En gang jobbet jeg med et team bestående av utviklere, designere, testere, devops, prosesseier og produkteier. Teamet var opptatt av å få med alle sine meninger, for det var viktig at alle ble hørt. Hver og en av oss tok en bunke post-it lapper og tusj. Vi fikk ti minutter til å skrive ned tanker og ideer i stillhet. En og en fra teamet fikk så henge opp sine post-it lapper på veggen og snakke om hva den handlet om foran de andre. På denne måten fikk alle formidle sine tanker og ideer som ble delt med resten av teamet. Til slutt hadde vi avstemning. Hvert teammedlem fikk tre røde prikker som kunne klistres på de lappene som man syntes burde diskuteres videre eller fortjente å være med videre til neste syklus.</p><h4>Hvorfor?</h4><p>Vet du meningen bak hvorfor akkurat <em>du</em> og <em>teamet ditt</em> eksisterer? Hvorfor dere skal løse de utfordringene dere er tildelt, og hvorfor du og dine egenskaper er viktig for å løse dem? Jeg husker godt da teamet mitt benyttet teknikker fra Simon Sinek’<a href="https://www.amazon.com/gp/product/B005JZD3B4/ref=kinw_myk_ro_title"> bok</a> og<a href="https://www.ted.com/talks/simon_sinek_how_great_leaders_inspire_action"> TED foredrag</a>,<a href="https://www.amazon.com/gp/product/B005JZD3B4/ref=kinw_myk_ro_title"> Start with Why</a>. Simon har laget en modell han kaller “The Golden Circle”, der han snakker om hvordan store ledere verden over inspirerer til innovasjon og definerer suksess; svaret er å starte med “Why”:</p><ul><li>”<em>hvorfor eksisterer vi som team i denne virksomheten?</em>”</li><li>“<em>hvorfor er jeg i teamet og hva kan jeg bidra med?</em>”</li><li>“<em>hvorfor er vi viktig for virksomheten, brukerne eller kundene?</em>”</li><li>“<em>hvorfor eksisterer produktene våres?</em>”</li><li><em>“hvorfor skal kundene bruke produktene vi lager?”</em></li></ul><p>Modellen fokuserer på <strong>hvorfor</strong>, fremfor <strong>hva</strong> og <strong>hvordan</strong>.</p><h4>Oppsummering: Individuell og kreativ tenking</h4><p><em>Selv tror jeg, at når enkeltmenneske kan reflektere og tenke individuelt, vil man få frem utrolig mange ulike ideer, meninger og følelser. Jeg tror også at det skapes flest ideer, og at de beste beslutningene blir tatt, når man får flest mulig perspektiver inn i diskusjonene, og hver person kan tenke for seg selv uten forstyrrelser. Det er viktig å finne ut hvem man selv er i teamet, og hvor man kan bidra med sine styrker. Simons Sinek’ modell, hjalp teamet mitt med å få et godt overblikk på hver enkeltes bidrag, ansvaret de hadde og hvorfor vi individuelt og teamet eksisterte. Retrospektiv er en veldig god aktivitet for alle mulige team, men jeg tror det er spesielt nyttig der teamene er tverrfalige. De ulike fagrettningene kan oppleve forskjellige utfordringer og kan dele de med resten av teamet. Mange teknikker i smidig utvikling handler om å prate og jobbe sammen som ett lag. Og det er jo fint det, men jeg har også opplevd når man jobber i workshops, at det er lett for at personene som har flest ideer eller de som snakker mest, ofte sitter med fasiten. Retrospektiv muliggjør for at alle kan tenke frem sine ideer og dele de med hele teamet. Fordi alle ideene, meningene og menneskene blir tatt seriøst, og er like viktige.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3243f38daab8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dfind-consulting/erfaringer-fra-arbeid-i-tverrfaglige-team-3243f38daab8">Erfaringer fra arbeid i tverrfaglige team</a> was originally published in <a href="https://medium.com/dfind-consulting">Dfind Consulting</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[About Writing Positive and Negative Variable Names]]></title>
            <link>https://medium.com/dfind-consulting/about-writing-positive-and-negative-variable-names-b42328d51e9c?source=rss-830a2ef44966------2</link>
            <guid isPermaLink="false">https://medium.com/p/b42328d51e9c</guid>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[systemutvikling]]></category>
            <category><![CDATA[readability]]></category>
            <category><![CDATA[code]]></category>
            <dc:creator><![CDATA[Marius Ibsen]]></dc:creator>
            <pubDate>Wed, 26 Oct 2022 16:57:31 GMT</pubDate>
            <atom:updated>2022-12-09T08:34:35.503Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NcYlXOfb8Wdwa_jP" /><figcaption>Photo by <a href="https://unsplash.com/@zacdurant?utm_source=medium&amp;utm_medium=referral">Zac Durant</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Sometimes I see developers define variable names such asisNotSelected, hasNoData and shouldNotInclude. I avoid writing variable names like this as much as possible. Declaring variables like so focuses on the negative outcome. Variables written in a non-active, negative or reversed way give a feeling that the returned value is something we don’t want or that is not positive and good. Instead, writing code that focuses on something active, positive, or forwarding will make the code-reading experience more efficient and less frustrating.</p><h3>Variable naming: positive vs negative</h3><p><strong>We force our brains to think reversely</strong> when naming variables based on the negative outcome. Doing so is more strenuous than thinking in an active or forward way.</p><p><strong>The code we are producing should be easy to read and make sense. </strong>Naming our variables on the <em>positive</em> outcome is better for a developer’s reading experience because it feels active and valuable. If we eventually want the opposite outcome, the non-active or negative, we invert it when necessary. In my opinion, It’s easier to think that something is <em>active</em> and <em>inactive</em> instead of <em>in-active</em> and <em>not in-active. </em>Let’s make a comparison:</p><p><strong>Negative named variable:</strong></p><pre>const isNotActive = true<br>isNotActive // true</pre><p><strong>Positive named variable:</strong></p><pre>const isActive = false<br>isActive // false</pre><h3>Inverting</h3><p><strong>The exclamation mark (!)</strong> is almost ubiquitous in programming languages and is a suitable replacement for words like <em>no</em>, <em>not</em> and <em>doesn’t</em>. For instance, we can turn a boolean state to the opposite by using an exclamation mark.</p><p><strong>Use exclamation marks to turn positive to negativ (or the other way)</strong>. In When we see an exclamation mark on a variable that is initially based on something active or a positive outcome, developers generally know that the condition will turn to the opposite value. In the code example below, we could prepend exclamation marks to isNotActive<strong> </strong>and isActive. Still, the isActive variable would be easier to read for the common eye because it has an <em>active</em> state in the first place. On the other hand, when we initially base our variable name on the negative outcome, the results are not quite so clearly.</p><p><strong>Negative named variables:</strong></p><pre>const isNotActive = true<br>const hasNoData = true<br><br>if(isNotActive &amp;&amp; hasNoData) {<br>  // not active<br>}<br><br>if(!isNotActive &amp;&amp; !hasNoData) {<br>  // active<br>}</pre><p><strong>Positive named variables:</strong></p><pre>const isActive = false<br>const hasData = false<br><br>if(!isActive &amp;&amp; !hasData) {<br>  // not active<br>}<br><br>if(isActive &amp;&amp; hasData) {<br>  // active<br>}</pre><p>Working with arrays could be another example. Let’s say we have an array of vegetables and want to be sure that it does not contain <em>carrots</em>. We could make a couple of variables named doesNotContainsCarrots<strong> </strong>or containsCarrots and wrote the code like so:</p><p><strong>Negative named variable:</strong></p><pre>const vegetables = [&#39;potato&#39;, &#39;salad&#39;]<br>const doesNotContainsCarrots = vegetables.some(v =&gt; v !== &#39;carrot&#39;)<br><br>if(doesNotContainsCarrots) {<br>   // does not contain carrots, no chopping<br>}<br><br>if(!doesNotContainsCarrots) {<br>   // contains carrots, chop chop<br>}</pre><p><strong>Positive named variable:</strong></p><pre>const vegetables = [&#39;potato&#39;, &#39;salad&#39;]<br>const containsCarrots = vegetables.some(v =&gt; v === &#39;carrot&#39;)<br><br>if(!containsCarrots) {<br>   // does not contain carrots, no chopping<br>}<br><br>if(containsCarrots) {<br>   // contains carrots, chop chop<br>}</pre><p>Like previous examples, it’s easier to read and think that something <em>exists</em> and invert it if we want the opposite outcome (<em>positive</em> to <em>negative</em>).</p><h4>Consistency Throughout the codebase</h4><p>We write code that should function, exists and work. Refactoring will become easier if the naming of variables follows a specific format. How we name variables, functions, enums or types in our code should be consistent throughout the codebase to avoid confusion. Naming things both positively and negatively in the same file or within the same scope should also be avoided. If that is the case, we should choose to go for either the positive or negative naming style since mixing is confusing. But in the end, I guess you will choose to go with <em>positive</em> and <em>active</em> naming simply because it feels more natural.</p><h3>Summarize</h3><p>Writing code that focuses on the active state and should return a positive outcome in our variable increases readability. By doing so, we don’t have to think in reverse. The state would be easier to revert since you always turn something active to not active, and lastly, we will focus more on what we need in our code instead of what we don’t need. Finally, our code would be easier to keep consistent because we follow a specific format for naming variables (and functions, types, etc.) Code must be easy to read, and we should write variable names with that in mind.</p><p><em>Code foh shizzle</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b42328d51e9c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dfind-consulting/about-writing-positive-and-negative-variable-names-b42328d51e9c">About Writing Positive and Negative Variable Names</a> was originally published in <a href="https://medium.com/dfind-consulting">Dfind Consulting</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaZone 2022 — Key takeaways]]></title>
            <link>https://medium.com/dfind-consulting/javazone-2022-key-takeaways-b344a33962f9?source=rss-830a2ef44966------2</link>
            <guid isPermaLink="false">https://medium.com/p/b344a33962f9</guid>
            <category><![CDATA[systemarkitektur]]></category>
            <category><![CDATA[systemutvikling]]></category>
            <category><![CDATA[javazone]]></category>
            <category><![CDATA[ux-design]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Marius Ibsen]]></dc:creator>
            <pubDate>Sun, 25 Sep 2022 21:50:58 GMT</pubDate>
            <atom:updated>2022-09-26T10:45:39.148Z</atom:updated>
            <content:encoded><![CDATA[<h3>JavaZone 2022 — Key takeaways</h3><h4>JavaZone er en av verdens største samfunnsdrevne konferanser og tar for seg ulike temaer innenfor teknologi, sikkerhet, UX og ledelse. Konferansen gikk over to dager med fullpakket program og mange interessante<strong> </strong>foredrag.</h4><p>Skrevet av <a href="https://medium.com/@mathias.hartveit"><strong>Mathias Hartveit</strong></a><strong> og </strong><a href="https://marius-ibsen.medium.com/"><strong>Marius Ibsen</strong></a></p><p><em>Som alle tidligere år ble JavaZone holdt i Oslo Spektrum. Konferansen hadde mer enn 3200 deltakere, over 100 foredrag og foredragsholdere.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wSQSpqbrXGVXOyQuJoQMCQ.jpeg" /><figcaption><a href="https://www.instagram.com/p/CiQCSulKngJ/?utm_source=ig_web_copy_link">https://www.instagram.com/p/CiQCSulKngJ/?utm_source=ig_web_copy_link</a></figcaption></figure><p>Vi har tatt med oss mange erfaringer fra årets JavaZone som vi syntes er viktig å belyse. Erfaringene og kompetansen vi har tatt med i år handler hovedsakelig om mennesker.</p><h3>Utvikling handler om mennesker</h3><p>Utviklere blir mer og mer tilknyttet flere deler av organisasjonen og tar valgene som tidligere ble tatt av personer uten innsikt eller kunnskap om faget. Dette kommer nok av at man forstår bedre hva utviklerrollen er og at den kan flettes inn med de andre fagdisiplinene i organisasjonen.</p><p>På JavaZone i år delte flere foredragsholdere om egne erfaringer som ikke nødvendigvis hadde hovedfokus på kode. Det handlet også om mennesker, forventninger til utviklere og at utvikling ikke alltid trenger å være så seriøst.</p><p>Hva betyr det å være en god utvikler? Christin Gorman fra Kodemaker mener at vi må oppdatere hvilke forventninger om hva programmering egentlig er; dette snakket hun om i foredraget<a href="https://2022.javazone.no/#/program/a28cd1fa-9696-4a1f-97b0-ce1c0bbad6dc"> <em>What makes a good developer?</em></a>. Det som forventes av en utvikler i dag er gode mattekunnskaper og å kunne skrive algoritmer. Programmering som fag blir ofte fremstilt som en idyllisk verden hvor det ikke oppstår problemer eller utfordringer men dette stemmer ikke overens med virkeligheten. Utviklere opplever utfordringer i hverdagen slik som i andre jobber, vi løser bare ulike utfordringer og har andre behov.</p><p>Forventningene som stilles i dag er nesten irrelevant og langt ifra hva en utvikler faktisk jobber med. Utviklere flest bruker svært lite matematikk i det daglige, og de færreste av oss skriver en algoritme. Det er hverken nødvendig med gode mattekunnskaper eller å kunne skrive algoritmer for å være en god utvikler. Christin mener vi bør fokusere på andre egenskaper som er mer nødvendige og relevante for det arbeidet vi driver med. Hvordan man jobber med mennesker og forstå problemene vi må løse for menneskelige behov er av viktigere art; en utvikler programmerer hovedsakelig løsninger for å løse menneskelige utfordring. Christin nevner tre egenskaper man bør se etter når man skal rekruttere nye talenter:</p><ul><li>De viktigste egenskapene en utvikler må ha er <em>tålmodighet</em> og <em>utholdenhet</em>.</li><li>Jo mer vi kan av det grunnleggende desto bedre valg kan vi ta i fremtiden.</li><li>Vi trenger mer menneskelig interesse. Vi må bry oss om menneske vi lager løsninger for, og vi må forstå utfordringene brukerne våre opplever.</li></ul><p>Stian Veum Møllersen fra NRK tok oss med på en <a href="https://2022.javazone.no/#/program/8c383c4d-e6ab-44f0-a5a2-ae0782d20e9f"><em>røverhistorie</em> om Popcorn og klokker</a>. For noen år siden startet han et moro-prosjekt for å gjenskape låten Popcorn, en meme-låt fra 1969. Prosjektet gjorde at man måtte løse ulike problemstillinger og finne riktige datastrukturer for å håndtere tid og lyd synkront i nettleseren. Utfordringene han måtte løse gjorde at han fikk innsikt i flere av nettleserens verktøy, som blant annet setInterval, setTimeout, requestAnimationFrame og WebAudio-klokka. En annen foredragsholder, Vegard Veiset fra Bekk, viste frem sin hjemmesnekra spillmotor laget i Kotlin. Spillmotoren hadde han laget fordi han ville forstå hvordan en spillmotor fungerer, ikke for å faktisk lage spill. Prosjektet hadde han jobbet med i over fire år på hobbybasis.</p><p>Både Stian og Vegard lagde noe med interesse for å løse andre problemer enn det de vanligvis støttet på. De trengte ingen spesiell grunn eller mening de ville bare gjøre noe gøy for å lære seg ny kunnskap. Det vi lager trenger ikke være seriøst eller nyttig, ei heller profesjonelt for å være lærerikt. Det viktigste er at man får noe ut av det man lager</p><p>Nina Bakken, designer i NAV, hold innlegget <a href="https://2022.javazone.no/#/program/77ba7dac-424f-401f-ac34-2539aeba2807"><em>Fart, flyt og hyppige leveranser = bedre brukeropplevelse</em></a> hvor hun delte erfaringer om det å lære et team å arbeide sammen i smidige prosesser. Essensen av smidig utvikling handler om å gjøre små ting, ofte. Ved å gjøre dette, vil man redusere risiko ved store lanseringer. Smidig utvikling handler også om kontinuitet, og at man jobber med små porsjoner som kan lanseres hele tiden. En typisk designmetodikk går gjennom flere steg — ide, konsept, testing og utvikling. Utviklere jobber gjerne etter en kortere prosess hvor de “slipper unna” de stegene som <em>ikke</em> har med utvikling å gjøre og feil fikses ofte umiddelbart. Hvis man får alle de ulike fagdisiplinene til å arbeide sammen som et team, så er det ikke noe i veien for at alle de tverrfalige rettningene kan jobbe slik utviklere gjør. Det bør ikke være separate faser men noe som skjer kontinuerlig. Innsikt, konsept, testing, utvikling og videreutvikling er noe man alltid må gjøre uansett.</p><p>Inkludering av de tverrfaglige fagrettningene i hverandres prosesser vil etter hennes mening gi økt fart, flyt og hyppigere leveranser. Åpenhet om kode og design vil skape mindre usikkerhet i teamet. Det er viktig å kunne vise frem og snakke om uferdig arbeid for å unngå tap av innsikt og læring. Hun trekker frem noen tilnærminger som har fungert bra for deres team, blant annet parprogrammering, par-design og datadreven utvikling.</p><p>Samlingen av disse foredragene og tilnærmingsmåtene danner et bilde av en norsk industri i vekst hvor fokuset på den tekniske og den organisatoriske og menneskelige siden av utvikling blir mer sammenflettet.</p><h3>Fremtiden er Sosio-Teknisk</h3><p>Norske bedrifter og organer har over lengre tid hatt fokus på en digitaliseringsprosess av deres tjenester og produkter. Denne prosessen ser ut til å ha ført de fleste opp mot en felles problemstilling. <em>Hvordan skaper man og vedlikeholder IT-baserte team, programvare og prosesser som er bærekraftige, langsiktige og stabile for medlemmer, produktet og brukere?</em></p><p>Dersom man spør 10 bedrifter får man nok 10 forskjellige svar, og derfor er det veldig givende at mange av Norges IT-kjemper deltar på JavaZone for å dele sine erfaringer og anmodninger om hvordan nettopp de oppnår sine mål — uten å slite ut både teknologien og menneskene involvert.</p><p>Vipps utforsker sine utfordringer, opplevelser og erfaringer i foredraget <a href="https://2022.javazone.no/#/program/5a831bdc-03be-4142-9e47-ec24dd95713c"><em>Hva er digital produktutvikling? En historie fra Vipps.</em></a><em> </em>Moquan Chen og Marit Andreassen understreker viktigheten av å danne tverrfaglige og myndiggjorte team. Et myndiggjort team dannes når medlemmene har autonomi til å ta de valgene fagpersonene mener er best for å oppnå målet definert av ledelsen. For mye styring ovenfra fører til mikrostyring, noe som ofte fører til teknisk dårligere produkter og mindre eierskap for selve laget som utfører oppgavene. Man ønsker å teste teorier og hypoteser så tidlig som mulig i prosessen frem mot et produkt for å luke ut hvilke muligheter teamene har fremover.</p><p><a href="https://2022.javazone.no/#/program/85187a21-c215-43f8-90e8-88989b7a945d">Einar W. Høst fra NAV</a> mener at moderne utviklere og it-systemer er “sosio-tekniske” fenomener. Organisasjonens krefter påvirker utviklingen av programvare, som igjen påvirker arbeidsmåten til organisasjonen. Utviklere som ønsker å påvirke organisasjonen må være mer enn bare teknisk dyktige, de må også være sosialt dyktige. I foredraget tar Einar oss gjennom de personlige utfordringene som kan oppstå individuelt og internt i team som blir mer og mer myndiggjort i dagens landskap.</p><p>Det eneste som ser ut til å være sikkert i tverrfaglige, teknologiske og myndiggjorte team er at landskapet rundt endrer seg kjapt, og det endrer seg ofte. Dette gjelder både teknisk med tanke på teknologiske utfordringer og muligheter som åpner for nye løsninger, men også samfunnsmessige endringer. Lover og regler, fokus på nye brukergrupper eller endringer i brukernes daglige behov kan slå inn på hva fremtiden til teamet skal se ut som. Desto viktigere er det at teknologene er fokusert på å bygge bærekraftige løsninger. Med bærekraftige løsninger menes det tekniske løsninger som tåler endring og vedlikehold over lang tid, med skiftende fokus og landskap.</p><p><a href="https://2022.javazone.no/#/program/b0d4acb2-2255-48db-acf0-f1268017b49e">Kristofer Giltvedt Selbekk</a> deler sine erfaringer fra 10 år med design systemer og frontend komponentbibliotek for å belyse hvordan man designer React komponenter med fokus på den fremtidige utvikleren. <a href="https://2022.javazone.no/#/program/8a2fd154-b7d0-466c-99b4-ffce79cc6e2f">Vegard Haugstvedt</a> forteller om NAVs pågående arbeid med å digitalisere alle sine søknader. Til nå estimerer de at de har digitalisert om lag 300 søknader på 3 år! Teamet må underveis ta hensyn til flere lag med brukere, samt endringer i lover og regler, endringer i nav-kunders behov og ikke minst ønsker om å kunne bruke tjenesten <em>utenfor </em>den digitale sfæren.</p><p>Som deltaker på JavaZone 2022 har det vært svært givende å delta i diskusjonene og erfaringene som deles av mange av Norges fremste teknologiske bedrifter. Dette er utfordringer som er universelle for alle team i alle sektorer, og byr på et spennende blikk inn i fremtiden for mange “sosio-teknologer”.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b344a33962f9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dfind-consulting/javazone-2022-key-takeaways-b344a33962f9">JavaZone 2022 — Key takeaways</a> was originally published in <a href="https://medium.com/dfind-consulting">Dfind Consulting</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Git reflog: Restore Version Control History]]></title>
            <link>https://medium.com/dfind-consulting/restore-commit-history-with-git-reflog-67f7676e902f?source=rss-830a2ef44966------2</link>
            <guid isPermaLink="false">https://medium.com/p/67f7676e902f</guid>
            <category><![CDATA[git-reflog]]></category>
            <category><![CDATA[systemutvikling]]></category>
            <category><![CDATA[git-history]]></category>
            <category><![CDATA[version-control]]></category>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Marius Ibsen]]></dc:creator>
            <pubDate>Tue, 09 Aug 2022 14:06:26 GMT</pubDate>
            <atom:updated>2022-09-02T11:26:22.702Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NNpIKZmLZ8bDSz79" /><figcaption>Photo by <a href="https://unsplash.com/@vonshnauzer?utm_source=medium&amp;utm_medium=referral">Egor Myznik</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Did you know we can use Git reference logs to restore Git commit history(?) Often we developers experience challenges when working with Git. We can accidentally force-push commits to the remote main branch, complete a rebase that went bad, delete a branch we wanted to keep or hard reset to the wrong commit. In this post, we will look at git reflog and git reset. We will review some common scenarios on restoring local commits, restoring a deleted branch, and reverting force-pushed changes due to a rebase.</p><h3>Git reflog</h3><p><a href="https://git-scm.com/docs/git-reflog">git reflog</a> is a tool that can help us recover almost anything — at least everything we have committed. The tool keeps track of commits that have been created but also discarded ones in a log called the reference log. The reference log is kept on our local computer under the .git directory in a local repository. It contains a list of commits that HEAD has pointed to and keeps track of the entire history of a commit. Besides the reference log for branches, we have a separate reference log for stash.</p><p>It’s important to know that reference logs do <em>not</em> track in the remote repository, like pushes, fetches and clones; it is purely local and current to the working environment. Below is two screencaps, the first from Github Codespaces and the second from a local filesystem that initially created all the commits of the main branch in the <em>same</em> repository:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*L1DTjYe4kiUo01_95hL-dQ.png" /><figcaption>Reference log from a workspace in Github Codespaces</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*d175xjAzVotgtgHlFvjtQg.png" /><figcaption>Reference log from local computer where the commits were initially created</figcaption></figure><p>Records of the history on a branch will expire after 30 days by default. We can change the expiration days running git reflog —expire if we want to keep the history for a longer time or just want to change the duration.</p><h3>Git log vs reflog</h3><p><a href="https://git-scm.com/docs/git-log">git log</a> is a command that shows a list of commits related to a branch.git reflog is similar to git log but shows a list of snapshots and times when HEAD was changed. reflog can also reference other types such as <em>stash</em>, <em>branches</em>, <em>rebase, merge</em> and <em>tags</em>. A reference is known as <em>refs</em>, and the syntax for accessing these is name@{qualifier}. Running git reflog is the most basic use case and essentially the equivalent of writing git reflog show HEAD. The output will look like this:</p><pre><strong>=&gt;</strong> git reflog</pre><pre>47efaa2 HEAD@{0}: commit: refactor: remove post schema<br>f243f12 HEAD@{1}: commit: refactor: change author fields<br>4783ba0 HEAD@{2}: commit: chore: add .env to gitignore<br>a19d142 HEAD@{3}: commit: chore: update readme<br>f5ade9a HEAD@{4}: commit: chore: update yarn.lock<br>854c08f HEAD@{5}: commit (initial): feat: bootstrap sanity studio</pre><h3>Git reset</h3><p><a href="https://git-scm.com/docs/git-reset">git reset</a> is a command we can use to move back to a previous commit, discarding or undoing previous changes. We can run git reset --hard &lt;commit_sha&gt; to move our branch back in the commit history.</p><ul><li><strong>A hard reset</strong><em> </em>(git reset --hard) will <em>completely destroy</em> any changes and remove them from your local repository.</li><li><strong>A soft reset</strong><em> </em>(git reset --soft) will keep your changes, and stage them back automatically.</li><li><strong>A mixed reset</strong> (git reset --mixed) which is the default, will keep you changes but they will also become unstaged. Even tho it is flexible, you will have to stage the changes manually.</li></ul><h3>Restore local commits</h3><h4><strong>Scenario</strong></h4><p>We have made some commits that haven’t been pushed to the remote repository yet. We do a git reset —-hard &lt;commit_sha&gt; to a previous commit, and our local branch is set back to an earlier point and discarded all history after the chosen commit. We then run git log and see that the commits are gone. We cannot pull the changes from the remote repository since we never synced the changes.</p><h4><strong>How to restore</strong></h4><p>When running git reflog we can see that our changes still are tracked by the reference log; we even have a separate commit for the hard reset that we did earlier:</p><pre><strong>f243f12 HEAD@{0}: reset: moving to f243f12</strong><br>eec6f27 HEAD@{1}: commit: refactor: author should not have image<br>47efaa2 HEAD@{2}: commit: refactor: remove post schema<br>f243f12 HEAD@{3}: commit: refactor: change author fields</pre><p>With this information, we can reset our branch back to the state we discarded by using one of the references in the reflog. We can move our branch to the selected commit by running git reset --hard &lt;commit_sha&gt;:</p><pre><strong>=&gt;</strong> git reset --hard f243f12<strong><br>=&gt;</strong> git reflog</pre><pre>f243f12 HEAD@{0}: reset: moving to eec6f27<br>f243f12 HEAD@{1}: reset: moving to f243f12<br>eec6f27 HEAD@{2}: commit: refactor: author should not have image<br>47efaa2 HEAD@{3}: commit: refactor: remove post schema<br>f243f12 HEAD@{4}: commit: refactor: change author fields</pre><h3>Restore a deleted branch</h3><p>We can recover deleted branches using SHA’s in the reference logs.</p><h4>Scenario</h4><p>Not uncommonly, we might checkout a new branch in our local environment. We could have a branch called chore/update-packages and commit a change that adds <a href="https://day.js.org/">dayjs</a> as a package:</p><pre><strong>=&gt; </strong>git checkout -b chore/add-dayjs-package<strong><br>=&gt; </strong>yarn add dayjs<strong><br>=&gt; </strong>git add .<strong><br>=&gt;</strong> git commit -m &#39;chore: add dayjs package&#39;</pre><pre>5a75042 HEAD@{0}: commit: chore: add dayjs package</pre><p>At a later point, we checkout the <em>main</em> branch and deletes the chore/add-dayjs-package branch — maybe we did not need it anymore for some reason:</p><pre><strong>=&gt;</strong> git checkout main</pre><pre>47efaa2 HEAD@{0}: moving from chore/add-dayjs-package to main</pre><pre><strong>=&gt;</strong> git branch -D chore/add-dayjs-package</pre><pre>Deleted branch chore/add-dayjs-package (was 5a75042)</pre><p>We will get a confirmation message that git deleted the branch. After a while, we discover that we could need the changes after all, so how do we get them back?</p><h4>How to restore</h4><p>We can undo these changes with git reflog and git checkout. If we run git reflog we won’t see any references to the deleted branch. We could use the commit SHA provided in the delete message (5a75042) to revert the latest commit on that branch. But if we have lost the message, we need to use the reference log. And if you named your commits well, it should be easy to find the missing commit:</p><pre><strong>=&gt;</strong> git reflog</pre><pre>// deletion of a branch is not logged to reflog<br>47efaa2 HEAD@{0}: moving from chore/add-dayjs-package to main<br><strong>5a75042 HEAD@{1}: commit: chore: add dayjs package</strong><br>47efaa2 HEAD@{2}: moving from main to chore/add-dayjs-package</pre><p>We can now checkout the deleted commit SHA and create a new branch from that commit running git checkout -b &lt;branch_name&gt;:</p><pre><strong>=&gt;</strong> git checkout 5a75042<br><strong>=&gt;</strong> git checkout -b chore/add-dayjs-package</pre><h3>Revert force-pushed changes</h3><h4>Scenario</h4><p>We reset our branch using git reset —-hard to an earlier commit and run git push — force to override any changes that we otherwise could pull from the remote repository. But at some point, we want those changes back.</p><pre>=&gt; git reset --hard &lt;commit_sha&gt;<br>=&gt; git push --force</pre><h4>How to restore</h4><p>We can use git reflog and git reset to restore force-pushed changes.</p><pre><strong>=&gt;</strong> git reflog<br>f243f12 HEAD@{0}: reset: a19d142 to f243f12</pre><p>By the log we can see that the message on HEAD@{0} is reset: a19d142 to f243f12, which means that commit with hash a19d142 was force-pushed by f243f12. That also gives us information about which commit we need to restore, the one with hash a19d142. We can simply do the same procedure as initially to move back to the overriden commit:</p><pre>git reset --hard a19d142<br>git push --force</pre><p>Finally, we force-push the new changes to the remote repository. Always be careful and check that you are on the correct branch before doing a force push. Especially to prevent that production code is not being affected or team member code is not being overwritten.</p><p>Thanks for reading! I hope you enjoyed this content. Feel free to clap, comment or share.</p><p><em>Code foh shizzle</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=67f7676e902f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dfind-consulting/restore-commit-history-with-git-reflog-67f7676e902f">Git reflog: Restore Version Control History</a> was originally published in <a href="https://medium.com/dfind-consulting">Dfind Consulting</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Scroll Hook with Shadows]]></title>
            <link>https://medium.com/dfind-consulting/react-scroll-hook-with-shadows-9ba2d47ae32?source=rss-830a2ef44966------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ba2d47ae32</guid>
            <category><![CDATA[systemutvikling]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[react-hook]]></category>
            <dc:creator><![CDATA[Marius Ibsen]]></dc:creator>
            <pubDate>Fri, 06 May 2022 21:34:11 GMT</pubDate>
            <atom:updated>2022-08-09T11:37:04.014Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ml53jqb5uYA704hbuPiK5A.jpeg" /><figcaption>Photo by: <a href="https://unsplash.com/@asci_en">https://unsplash.com/@asci_en</a></figcaption></figure><p>Have you ever thought of spicing up your scrollable content with nice-looking shadows? Yes, all browsers have the <em>scroll bar</em>, but we can make our content shine even better and, at the same time, improve usability. I think shadows add a smooth and excellent feel to our content and help by showing the users that “there is more content down here” or “there is more content up here”.</p><blockquote>TLDR: You will find the final source code at the bottom of the article</blockquote><h3>The Scroll Hook</h3><p>Recently, I’ve been working on a hook that adds inner shadows when scrolling an element with overflowing content. It is not very complicated, and it’s fun to make. We’ll break down the code throughout the post, look into how it works, and finally use it in our code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/154ecf87431923f99747b31da71175d4/href">https://medium.com/media/154ecf87431923f99747b31da71175d4/href</a></iframe><h4>Handling scroll events</h4><p>First, let’s go through the roll logic part of the hook. It’s not complicated, and I did not have to create three separate states for each event. But it is done for simplicity instead of holding an object with all the values.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/360751a2658643353a36a8f419148277/href">https://medium.com/media/360751a2658643353a36a8f419148277/href</a></iframe><p>onScroll is a React property that we can get on any scrollable HTML element for listening on <em>scroll events</em>, such as a div. It takes a function and returns an event of the target element. In native JavaScript, this would be somewhat equivalent to:</p><pre>element.addEventListener(‘scroll’, (event) =&gt; /* do something*/)</pre><p>The onScrollHandler-method (exported from the hook) we can pass as the value to the onScroll-property of our element. When scrolling the element, the onScroll-property fires and the onScrollHandler-method triggers. Then we can pick the properties scrollTop, scrollHeight and clientHeight from the event target and set them as values for their respective states.</p><p>The onScrollHandler-method (exported from the hook) we can pass as the value to the onScroll-property of our element. When scrolling the element, the onScroll-property fires scroll events, and the onScrollHandler-method receives these events. We can then pick the properties scrollTop, scrollHeight and clientHeight from the event target and set them as values for their respective states.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*cB16NN2s7k_3f-nW8smY_g.png" /><figcaption>Illustration of scrollHeight and clientHeight on an element with overflowing children elements</figcaption></figure><ul><li><strong>clientHeight </strong>(<em>visible content</em>) is the <em>inner</em> height of an element, including padding. We can calculate it by CSS height + CSS padding. If a horizontal scrollbar is present, the inner height includes the height of the scrollbar.</li><li><strong>scrollHeight </strong>(<em>visible + hidden content</em>) is the height of an element’s visible content, including hidden content not visible on the screen for an overflowing element.</li><li><strong>scrollTop</strong> is the number of pixels scrolled vertically on the content of an element. Measuring the value takes the distance from the top of an element to the topmost of visible content.</li></ul><p>(Read more about <a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollTop">scrollTop</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight">scrollHeight</a> and <a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/clientHeight">clientHeight</a> on MDN)</p><h4>Calculate shadow position</h4><p>We have to do some calculations to determine if and when we should show shadows on the <em>top</em>, <em>bottom</em>, or <em>both</em>. We want to show shadows concurrently when we’re neither at the <em>top</em> of the scroll nor the <em>bottom</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9fcc6ca9c4c03ea3f8bfcfbb8aeb724c/href">https://medium.com/media/9fcc6ca9c4c03ea3f8bfcfbb8aeb724c/href</a></iframe><ul><li><strong>isBottom </strong>is true when the inner height of the visible element equals the total height of the visible and hidden content minus (-) pixels scrolled from the top of the element.</li><li><strong>isTop </strong>is true when we’ve not scrolled yet, or scrollTop equals 0 pixels.</li><li><strong>isBetween</strong> is true when we’ve scrolled more than 0 pixels from the top, and the <em>inner heigh</em>t of the visible element is less (&lt;) than the visible plus (+) hidden content height minus pixels scrolled from the top.</li></ul><p>We can show this by example: we could have an element that has 400 pixels inner height [clientHeight], that is scrolled 150 pixels from the top [scrollTop]; we should then get that <strong>isBetween</strong> is true:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3d88c31a4c5a1d12774709b7da81f28/href">https://medium.com/media/b3d88c31a4c5a1d12774709b7da81f28/href</a></iframe><h4>Determine shadow type based on the calculated position</h4><p>Our getBoxShadow()-function handles the logic for determining and returning the correct CSS box-shadow value as a string. This value we want to set to the target element reactive as we scroll. We’re here using the variables — isBottom, isTop and isBetween —from earlier to determine which shadow to use:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd244c457001664fff144489f9a1b027/href">https://medium.com/media/dd244c457001664fff144489f9a1b027/href</a></iframe><p>We want to add shadow to the edge with overflowing content because it makes sense to the eye watching it. So, if we are at the top of the element, we show shadow at the <em>bottom</em>. If we are between (as we calculated in the previous code example), we want to show both <em>top</em> and <em>bottom</em> shadows, or else if we are at the bottom of the element, we want to show the <em>top</em> shadow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*1vDIJ5_pf17kz1tifdaBCw.png" /><figcaption>Illustration of inner box shadow top and bottom on an element with overflowing children elements</figcaption></figure><h3>Using the Scroll Hook</h3><p>Since this is a React hook, we need to create a component that can use it, and it should be straightforward since as there is to do is connect the props to the target element.</p><p>In the code block below, we have a component called App. We import the useScrollWithShadow-hook, destruct the onScrollHandler()-method and the boxShadow variable. We pass onScrollHandler() as the value of the div’ onScroll property and set boxShadow as an inline style.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d5502fbcba53852feaf3e18921c672a5/href">https://medium.com/media/d5502fbcba53852feaf3e18921c672a5/href</a></iframe><p>Without some content that overflows the element, this would not look or work very well. All it is left is to add some content to the div and maybe some static height so we can get an overflow. We could also add CSS transitions for even more smoothening. But from here on, I will leave the rest to your imagination.</p><p>Look at the final result for the styled solution with content and source code on Codesandbox.</p><h3>Final result</h3><p>Here is the final result. Click “toggle shadows” to switch between with and without shadows (<a href="https://codesandbox.io/s/upbeat-sun-zgyyo5">source code on Codesandbox</a>):</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fupbeat-sun-zgyyo5%3Ffontsize%3D14%26hidenavigation%3D1%26theme%3Dlight%26view%3Dpreview%26hidedevtools%3D1&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fupbeat-sun-zgyyo5%3Ffontsize%3D14%26hidenavigation%3D1%26theme%3Dlight%26view%3Dpreview%26hidedevtools%3D1&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fzgyyo5%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/0539ccf83b2c50d23410531b216ea8aa/href">https://medium.com/media/0539ccf83b2c50d23410531b216ea8aa/href</a></iframe><p>Thanks for reading! (feel free to clap and share if you liked this article)</p><p><em>Code foh shizzle</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ba2d47ae32" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dfind-consulting/react-scroll-hook-with-shadows-9ba2d47ae32">React Scroll Hook with Shadows</a> was originally published in <a href="https://medium.com/dfind-consulting">Dfind Consulting</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stop Overusing Console.log in JavaScript]]></title>
            <link>https://medium.com/dfind-consulting/stop-overusing-console-log-in-javascript-ff4b85df5268?source=rss-830a2ef44966------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff4b85df5268</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[developer-tools]]></category>
            <category><![CDATA[systemutvikling]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Marius Ibsen]]></dc:creator>
            <pubDate>Thu, 05 Aug 2021 19:02:10 GMT</pubDate>
            <atom:updated>2022-05-03T19:45:56.060Z</atom:updated>
            <content:encoded><![CDATA[<p>The web browser console gives us more options than just the console.log()</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qbSBSYYEKTSCfXF5gKz6qQ.png" /><figcaption>Image of a road sign containing the text: Watch out! overuse detected</figcaption></figure><p>OK, I admit it, and I’m not very a fan of it. Mostly I use console.log() for troubleshooting, checking that the arguments of a function get the correct values or that a function returns what I expect it to do. Sometimes I take shortcuts using the built-in browser method console.log() to clarify the result of some piece of code. On infrequent occasions, instead of rendering a ReactJS-component to the Graphical User Interface (GUI), I may print the component to the console to examine its properties.</p><p>I’ve seen many developers are using the web console in similar ways as I do. We developers should stop overusing the console.log() and instead draw advantages from what we can do with the web console than just reading simple logs.</p><p>I want to discuss some common issues and bad habits that we usually do and some solutions for using the console better.</p><h3>Issues and bad habits</h3><p>How often do we think about why we use the console.log() method, and in what contexts? Is it just purely automatic that we use it? Why do we always have to do all this logging, especially with console.log()?</p><p>In many of these situations, instead of <em>reading </em>and <em>understanding </em>the code, we make guesses and try to help ourselves by logging stuff to the console. All this time we spend on logging can be very time-consuming (sometimes it can even make us even more confused), and we probably “learn” slower.</p><h4>Unnecessary logging = less confidence</h4><p>An unnecessary amount of logging to the console makes us less confident. Developers often log to the console in many parts of the code — especially if functions are deeply chained — to “test” our code is reliable.</p><h4>Using the console for “confirmation”</h4><p>In far too many cases, we also accept that when logging something to the console, we get an indication that “everything works fine.” We can prevent building agents or scripts from breaking if we read and understand the code thoroughly instead of relying on the “confirmation” that the console may give us.</p><p>We often use this “confirmation” to check whether something is wrong or not, whether an object is undefined or an array has a length. I would say that “confirmation” is OK when our code breaks, and there are no other options.</p><h4>Debugging is time-consuming</h4><p>Debugging in the console may be time-consuming. Sometimes we can sit for days logging things to the console, taking away the focus on understanding how the code “actually” works and other options that we could have tried instead of just logging stuff.</p><h4>Logs may end up in production</h4><p>Logging to the console can be deployed in production, which is not always that great — especially if we log critical information that should not be available to “everyone” on the web.</p><h3>How we should use the web console</h3><p>What is essential to know is that the console also is a <a href="https://en.wikipedia.org/wiki/REPL">REPL</a>. That means we can interact with JavaScript on the page we’re inspecting. Using the REPL is a great way to play with and learn JavaScript.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IJD_qI9I0EBnjxkcxUvlAw.png" /><figcaption>Using the console REPL to add textContent to an HTML element with a wordmark CSS-selector. Here we add a string “Hello” above the Firefox logo.</figcaption></figure><h4>Useful console methods</h4><p>The overusedconsole.log() is just one of many methods we may call on the console object. console.error(), console.info(), and console.warn() may be better in cases where we will separate different states of messages. And, to get a better representation of our data in the console we can use methods like console.group() and console.table().</p><p><strong>console.error(): </strong>Prints an error message to the console, where the printed content will have a red colour. Most browsers also displays an error icon beside the console message.</p><p>console.error(‘Something is wrong’)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tYcFUWNQmHoWvGFQL6geeA.png" /></figure><p><strong>console.warn(): </strong>Prints a warning message to the console, where the printed content will have a yellow color. Most browser also displays an warning icon beside the console message.</p><p>console.warn(‘Heads up! This is a warning’)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*urjiiFrNXm3I2S_pYvVhBw.png" /><figcaption>Illustration: console.warn example in Firefox. console message with a yellow triangle containing an exclamation mark</figcaption></figure><p><strong>console.group(): </strong>Prints a group of console methods executed within the group. Such logging is usable when we need to do more than a single log in different files which is not related. We can also open and close groups in the console.</p><pre>console.group(‘feature’)<br>  console.warn(‘Heads up! This is a warning’)<br>  console.error(‘Something is wrong’)<br>console.groupEnd(‘feature’)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rMwm77JyiXtzVsSljonvtQ.png" /><figcaption>Illustration: console.group example in Firefox. console messages grouped within a console group called “feature.”</figcaption></figure><p><strong>console.table(): </strong>Prints a table representation of the data provided. The method accepts objects and arrays.</p><p>console.table([{ a: 1, b: 2 }])</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DB4_roBRCsKjULq_zPce-A.png" /><figcaption>Illustration: console.table example in Firefox. console messages are displayed in a table representation</figcaption></figure><h4>Some final words</h4><p>It’s not uncommon [for JavaScript beginners and professionals] to just print strings that say “works” or “done” or something similar and then use them to “confirm” that our code works as expected. I’ve seen far too many uses of console.log() in different places in a codebase simultaneously during a pair programming session.</p><p>Browser consoles are great tools, and we should use the great utils they provide to our benefit; testing JavaScript methods or extracts, playing with Document Object Model (DOM) or objects in our code. We can do much more with the console than log simple strings, numbers, or lengths on a list.</p><p>We should focus on understanding the underlying code and using the console for its benefits and not as a tool for confirmation; then, we will learn faster, become more confident and write better code in the future.</p><p>Thanks for reading</p><p><em>Code foh shizzle</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff4b85df5268" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dfind-consulting/stop-overusing-console-log-in-javascript-ff4b85df5268">Stop Overusing Console.log in JavaScript</a> was originally published in <a href="https://medium.com/dfind-consulting">Dfind Consulting</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[3 Ways of Rendering on The Web]]></title>
            <link>https://medium.com/compendium/3-ways-of-rendering-on-the-web-4363864c859e?source=rss-830a2ef44966------2</link>
            <guid isPermaLink="false">https://medium.com/p/4363864c859e</guid>
            <category><![CDATA[client-side-rendering]]></category>
            <category><![CDATA[server-side-rendering]]></category>
            <category><![CDATA[brukeropplevelse]]></category>
            <category><![CDATA[teknologi]]></category>
            <category><![CDATA[static-site-generator]]></category>
            <dc:creator><![CDATA[Marius Ibsen]]></dc:creator>
            <pubDate>Wed, 07 Apr 2021 19:09:06 GMT</pubDate>
            <atom:updated>2021-08-05T19:29:21.867Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7dBNjQdeJMqmTNVI8eqX5A.jpeg" /><figcaption>Illustration: Colored pixels being painted on a background</figcaption></figure><h4>Introduction</h4><p>Rendering a website can be done in several ways. A common challenge is when to choose which of the types.</p><p>Exploring the options before starting a new project can prevent us from refactoring parts of our code or the entire tech stack. It depends on whether it is crucial to get a good ranking in Google. Or if the content should be more interactive, dynamic, and fade smoothly into the user’s view. Or if performance and excellent user experience are more essential for your business goals.</p><p>All websites have different needs and having some basic understanding of the rendering on the web will spare you money, time, and frustration.</p><h3>Concepts and terminology</h3><p>First, we will go through some basic technical concepts and terminology. Knowing a little about them will help us make even better decisions on our website’s rendering options.</p><p>These concepts we can divide into two categories: Performance and Rendering.</p><h4>Performance</h4><ul><li><strong>Hydration</strong> is a technique where JavaScript converts static HTML (returned from the Server) into dynamic and interactive elements in the browser. Also generally referred to as client-side hydration or re-hydration. When hydrating, JavaScript (such as event handlers, listeners, etc.) is linked to the static HTML to make it interactive.</li><li><strong>Pre-rendering</strong> is a technique where the HTML is rendered <em>A Head of Time </em>at build-time. Pre-rendering is essential for public pages that should get crawled and ranked by search engines. Server-side and Static-side applications use this technique.</li></ul><h4>Rendering</h4><ul><li><strong>First Paint</strong> (FP) is the first step during rendering after a user navigates to a page. It is the first pixel painted on the screen and in the browser window — everything in the browser window that is visually different from before navigation is processed in the First Paint.</li><li><strong>First Contentful Paint</strong> (FCP) is the first time the browser renders something to the DOM, such as text, images, or SVG’s. During this process, the browser will tell the user that “something is happening.”</li><li><strong>Time to Interactive</strong> (TTI). The browser has rendered the entire website content, at this point, and the user can interact with the elements on the page. That could be pressing a button or clicking in text fields that give some feedback to the user.</li></ul><h3>Client-Side Rendering (CSR)</h3><p>Client-side rendered websites do everything “on their own.” Such as retrieve data from an API, manage logic, and routing between pages directly in the browser. Every page the visitor visits and its respective URL are being created dynamically.</p><p><em>We can think of rendering on the Client like package delivery, of three packages. Each package will come in a different order and at different times, but you don’t know precisely when. You will get the first package, then the second, and at last the third.</em></p><p>Client-side applications typically have a fast FP and FCP. They use hydration which can cause a slow <em>Time to Interactive</em> because the browser needs to “boot up” the JavaScript code, rehydrate, and then load the HTML back into the browser window. The hydration process may vary in time depending on how much JavaScript your application contains.</p><p>A slow TTI is not very good for <em>Search Engine Optimization</em> (SEO). Most Client-side applications that need their content crawled and optimized for SEO will have to implement pre-rendering to make it work properly.</p><p>Client-side rendering is the default for JavaScript applications. Popular Frontend Frameworks like React, Angular, and Vue use this rendering type.</p><h4>Pros:</h4><ul><li>Gives the user quick feedback and a smooth user experience, e.g., a fast First Contentful Paint.</li><li>Low server load because all the content is processed and rendered on the client/in the user’s browser.</li><li>Lower costs than a Server-side rendered application.</li></ul><h4>Cons:</h4><ul><li>May cause poor user experience. Potentially, leave the user waiting for content until everything is fully loaded into the browser, resulting in the user leaving the site instead.</li><li>Client-side applications make it hard for search engine robots to see the website content, which leads to no or poor indexing.</li><li>JavaScript pages will not be visible if JavaScript is disabled in the users’ browser.</li></ul><h3>Server-Side Rendering (SSR)</h3><p>Server-side rendering (SSR) happens On-demand, also called <em>Just in Time </em>(JIT). Every time the Client makes a request for a page, the Server generates HTML for that request. The HTML is then returned to the Client, wholly rendered, ready to be displayed.</p><p><em>We can think of rendering on the Server like package delivery, much like for Client-side rendering. Instead of getting the packages delivered at different times, you get all at the same time.</em></p><p>Server-side rendering is slower than Static-side rendering because the HTML is generated entirely on each request. But it’s faster than a client-side rendered application when returning the entire result to the user.</p><p>JavaScript frameworks like Vue and React use <em>hydration</em> to generate interactive code sent from the Server.</p><h4>Pros:</h4><ul><li>Suitable for SEO-focused websites.</li><li>Gives the user a great user experience by delivering all content on request.</li></ul><h4>Cons:</h4><ul><li>It may be expensive. Require setup and managing of servers or server code besides frontend code.</li><li>If the Server is down, the website is also down.</li><li>It may require a backend/full stack developer in addition to a frontend developer.</li></ul><h3>Static-Side Rendering</h3><p>Static rendering happens at build-time. Every page is compiled and rendered as static HTML files <em>Ahead Of Time (AOT).</em> Files generated AOT means that we will produce an HTML file with a separate URL for each file. What is excellent about static websites is that they can be uploaded to a CDN and easily be moved to another source when needed without much work.</p><p><em>We can think of rendering an application statically, much like on the server, just that it is incredibly fast. The packages don’t need to be packed beforehand; they’re just shipped to you at once.</em></p><p>Statically rendered websites have some significant advantages. They are fast, have better reliability, and improved SEO. Websites generated statically have fast FP, FCP, and TTI.</p><p>A few months ago, I wrote an article about what benefits you can draw from having Static Generated Websites. You are welcome to read it: <a href="https://marius-ibsen.medium.com/benefits-of-static-websites-5fb187d1ffe6">Benefits of Static Websites.</a></p><h4>Pros:</h4><ul><li>Perfect for SEO-focused websites.</li><li>Reliable, excellent performance, secure, and scalable</li><li>Low costs; it can “live” on a Content Delivery Network (CDN)</li><li>Easy to move between hosting providers</li></ul><h4>Cons:</h4><ul><li>You are dependent on deploying the entire website in case of changes — like pushing news articles or products for an e-commerce shop.</li></ul><h3>Let’s wrap up</h3><p>If you ask yourself, “When should one be critical to the choice of rendering type?” this is just relevant when a website contains JavaScript.</p><p>CSR may provide a faster response (FCP) to the user. It is more interactive and perfect when content needs to be updated without contacting the Server. On the other hand, suppose you build a website with full JavaScript. In that case, some JavaScript frameworks like React, Vue, or Angular will, in most cases, only render an empty HTML page. Search engine crawlers will see these sites as completely blank until fully rendered.</p><p>Many JavaScript frameworks that have become popular in the past years have built-in Static Site Generation (SSG) and Server-side rendering, such as GatsbyJS and NextJS, supporting both SSR and SSG.</p><p>SSR and SSG are better for SEO. Both can display page content faster. They give a better user experience, and search engine robots will have it easier to rank your pages. Suppose you have a static website that consists only of HTML. In that case, you do not need to pay attention or worry about SEO optimization or excessive server load at all.</p><p>On the latest project I’ve been working on, we’ve used a combination of client and static rendering for a couple of years. Doing so is essential because the customer I work for has a website that is both a news page and contains pages where users can see their customer relationship behind some secured pages.</p><p>Going entirely for just server-side or just client-side, I would not recommend if you are in the same situation as I described above. Know when to use the different rendering types, and you will make fantastic websites that also give the user a great user experience.</p><p>Thank you for reading!</p><p><em>Code for shizzle</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4363864c859e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/compendium/3-ways-of-rendering-on-the-web-4363864c859e">3 Ways of Rendering on The Web</a> was originally published in <a href="https://medium.com/compendium">Compendium</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Length Units in CSS]]></title>
            <link>https://medium.com/compendium/length-units-in-css-263914aca2b?source=rss-830a2ef44966------2</link>
            <guid isPermaLink="false">https://medium.com/p/263914aca2b</guid>
            <category><![CDATA[teknologi]]></category>
            <category><![CDATA[kreativitet]]></category>
            <category><![CDATA[accessibility-design]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[brukeropplevelse]]></category>
            <dc:creator><![CDATA[Marius Ibsen]]></dc:creator>
            <pubDate>Fri, 18 Dec 2020 10:33:37 GMT</pubDate>
            <atom:updated>2021-08-05T19:27:38.974Z</atom:updated>
            <content:encoded><![CDATA[<h4>And Their Importance for Accessibility</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c-nWXWOh6cnQFWbsi8GRig.png" /></figure><h4>Introduction</h4><p>There are several options for which length units you can use to determine the size of different CSS properties. Knowing how the various length units work and how to take advantage of them can be a key to generating clean style sheets, great user experiences, and inclusive websites.</p><p>A CSS declaration includes a <em>property / value</em> pair. The property value can include an integer or a keyword, a combination of keywords and integers, values with or without a CSS unit.</p><p>A length unit determines the size of a property. Most CSS properties accept a set of datatypes containing values and units. A paragraph, for instance, has the property max-width. We can assign the property max-width a <em>value</em>, and the <em>value</em> becomes part of the length unit.</p><pre>p {<br>  max-width: 200px;<br>}</pre><p>We have different categories of CSS length units: <em>absolute</em>, <em>relative</em>, and <em>viewport</em>.</p><h3>Absolute length units</h3><p>The so-called absolute length units have a fixed size. They don’t inherit from a parent element or change along with the viewport’s dimensions. Therefore they’re not recommended for use on screens, because they vary much in size, height, and width. Absolute CSS units will look the same, whether on desktop, tablet, or mobile, and are generally considered as always to be the same size.</p><h4>px</h4><p>The px unit is absolute. 1px is equal to a single point (“dot”) on a screen and is relative to the viewing device.</p><p>This length unit is not related to the current font neither to centimeters or inches. px is also a bit odd to use since it’s relative to a physical property and it messes up websites where zooming may be a need for users.</p><p><strong>Example</strong>: A element with a width property containing a value and px as unit.</p><pre>.element {<br>  width: 200px;<br>}</pre><h4>in, cm, mm</h4><p>The absolute length units in (inches) cm (centimeters), and mm (millimeters) are not very typical in use on the web. Neither are they recommended or accurate enough for websites either.</p><p>These units are suitable for physical media, like papers, posters, and other printed work.</p><pre>1in = 2.54cm = 96px</pre><pre>1cm = (96 / 2.54) = 38px</pre><pre>1mm = 0.1cm = 3.78px</pre><h3>Relative length units</h3><p>Relative length units are beneficial for making responsive and accessible websites. They scale relative to a parent or the viewport, and style sheets written with relative units can more easily scale from one environment to another, like fram a desktop to a mobile screen.</p><p>Relative units are primarly of interest for the typography in your web designs. A good strategy for web design would be to set font sizes to a relative rather than absolute. Then it is easier to double or half the size of something instead of setting explicit values, like an image of 400px.</p><h4>em</h4><p>The em unit is relative to the current font size of the element.</p><p>em<strong> </strong>and rem units are practical for creating entirely scalable and flexible layouts. If a user resizes their text or changes the font size in the stylesheets to something larger or smaller, the em unit will scale proportionally.</p><p><strong>Example</strong>: We want the font size of a child element to the half of the parent element — it can be a subtitle in the main heading. If the font size of the main heading is 44px, the child will become 22px.</p><pre>.child {<br>  font-size: 0.5em;<br>}</pre><h4>rem (“root em”)</h4><p>The rem unit is relative to the font size of the root element (e.g &lt;html&gt; or :root {}). As with em, the rem unit will scale but with the root element instead of a parent.</p><p><strong>Example</strong>: Titles are often larger than body text. The :root font-size is 16px. We would like that all H1-elements should be twice the size. Instead of defining 32px to a H1-element (which is first of all fixed and will not make it relative to other than itself), we can use rem instead:</p><pre>h1 {<br>  font-size: 2rem;<br>}</pre><p>A rem unit is so useful that it also scales with the user’s preferences in the browser. Most browsers do have a default font-size, often set to 16px. If there were no default font-size property set on the :root element, the browser’s build-in font-size would be used instead and still scale the website correctly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*m3i5pm7GB8Lbou11cbElFw.png" /><figcaption>Change default font size in Firefox</figcaption></figure><p>Above is an example of the browser settings for font-size in Firefox.</p><h4>ch</h4><p>The ch (“character”) unit is relative to the width of the zero (0) character in the font for an element.</p><p>On a webpage, paragraphs and blocks of text should not be too long, either too short. This is essential for people who have cognitive disfunction or reading difficulties. With the ch unit, we can determine how many characters, e.g., a paragraph, should have on each line. It seems to be a standard agreement on the internet that a paragraph text <em>should not be more than 65–75 words per line</em> (including spaces) to be most readable.</p><p><strong>Example</strong>: A paragraph with 65 characters per line for best readability. Look at the difference in user experience in the two images below.</p><pre>p {<br>  max-width: 65ch;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LTGb5Tq7JEZRsQwakVuSSQ.png" /></figure><h4>ex</h4><p>The ex unit is relative to the <strong>x-height</strong> of the font. It is rarely used, but is much the same as the ch unit, just for height instead.</p><h3>Viewport length units</h3><p><em>Viewport length units</em> are useful sometimes as they’re always relative to the viewport’s size. Viewport units can be helpful in cases where percentage (%) is hard to make it work. The viewport is defined by the size of a browser window.</p><p>viewport == browser window size</p><h4>Viewport Height (vh)</h4><p>The vh unit is relative to 1% of the viewport height.</p><pre>1vh   = 1% of viewport height<br>100vh = 100% of viewport height</pre><p><strong>Example:</strong> We have a landing page where we want an image placed at the very top. The image should take up the entire screen height — like a full-screen section feeling — and when we scroll, the rest of the content will show up. The content below could take up half the viewport height:</p><pre><em>// See this example on </em><a href="https://codepen.io/lobunto/pen/wvzGqvO"><em>Codepen</em></a><em>.</em></pre><pre>.image {<br>  background: #F5BE70;<br><strong>  height: 100vh;</strong><br>}</pre><pre>.text {<br><strong>  height: 50vh;</strong><br>}</pre><h4>Viewport Width (vw)</h4><p>The vw unit is the similar to vh, but vw is relative to 1% of the viewport width.</p><pre>1vw   = 1% of viewport width<br>100vw = 100% of viewport width</pre><p><strong>Example</strong>: We want a left-positioned childdiv that takes up 50%width of a parent div, based on the width of the viewport.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GbWfXvAVf77IT25fPAlEFQ.png" /></figure><pre>// <em>See this example on </em><a href="https://codepen.io/lobunto/pen/GRjZvpY"><em>Codepen</em></a><em>.</em></pre><pre>.parent {<br>  width: 100%;<br>  height: 400px;<br>  background: #2B343C;<br>}</pre><pre>.child {<br>  <strong>width: 50vw;<br>  </strong>height: 300px;<br>  background: #F5BE70;<br>}</pre><h4>Viewport vs. Percentage</h4><p>Viewport sizes are similar to percentage units, but work differently.</p><p>Percentage units always inherit the <em>size</em> of their parent element, not the viewport. Viewport units are always calculated by the size of the viewport size, which means it can extend the size of it’s parent.</p><p><strong>Example: </strong>You have a parent div element with 400px of height and a child div element with a height of 100%, then the child div will in theory potentially be much higher or smaller than the size of the viewport.</p><p>Using 100vh instead, on the child element, we can ensure that it fills up 100% of the viewport’s height and not necessarily the parent div element. This can be very useful when having banners that take the full height of the screen featured on the top on the website.</p><p><em>(Illustrated in the image below)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M8Y3Qm86LAU1xhSYKrzfNg.png" /></figure><pre>// left side of example - <em>see this example on</em> <a href="https://codepen.io/lobunto/pen/eYdZEBB">Codepen.</a></pre><pre>.parent {<br>  height: 400px;<br>  background: #2B343C;<br>}</pre><pre>.child {<br>  <strong>height: 100%;</strong><br>  background: #F5BE70;<br>}</pre><pre>// right side of example - <em>see this example on</em> <a href="https://codepen.io/lobunto/pen/VwKazmd">Codepen.</a></pre><pre>.parent {<br>  height: 400px;<br>  background: #2B343C;<br>}</pre><pre>.child {<br>  <strong>height: 100vh;</strong><br>  background: #F5BE70;<br>}</pre><h4>Viewport Maximum (vmax) and Viewport Minimum (vmin)</h4><p>vmin (“viewport minimum”) is relative 1% of the minimum browser viewport‘s dimensions. 1vmin = 1vh or 1vw, based on whichever dimension of the viewport who is smallest.</p><pre>1vmin   = 1% of viewport height or width, whichever is smaller<br>100vmin = 100% of viewport height or width, whichever is smaller</pre><p>vmax (“viewport maximum”) is relative to 1% of the maximum browser viewport‘s dimensions, based on whichever dimension of the viewport who is largest.</p><pre>1vmax   = 1% of viewport height or width, whichever is larger<br>100vmax = 100% of viewport height or width, whichever is larger</pre><p><strong>When are they useful:</strong></p><p>vmin and vmax are particularly useful for typography. Typically we will use <em>@media queries</em> for setting different text sizes as the applications layout scale based on a variety of devices’ height and width — like mobile phones and desktop computers. It seems that finding the right values needs some tweaking and see how you want it.</p><pre>// See example on <a href="https://codepen.io/lobunto/pen/MWjyvoj">Codepen.</a></pre><pre>h1 {<br>  width 10vmin;<br>}</pre><p>Using relative CSS units is excellent for making websites that should be used for multiple device resolutions and focusing on accessibility and the best user experience.</p><p>Thanks for reading!</p><p><em>Code foh shizzle</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=263914aca2b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/compendium/length-units-in-css-263914aca2b">Length Units in CSS</a> was originally published in <a href="https://medium.com/compendium">Compendium</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Benefits of Static Site Generation]]></title>
            <link>https://medium.com/dfind-consulting/benefits-of-static-websites-5fb187d1ffe6?source=rss-830a2ef44966------2</link>
            <guid isPermaLink="false">https://medium.com/p/5fb187d1ffe6</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[static-site-generation]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[systemutvikling]]></category>
            <category><![CDATA[seo]]></category>
            <dc:creator><![CDATA[Marius Ibsen]]></dc:creator>
            <pubDate>Wed, 07 Oct 2020 20:57:52 GMT</pubDate>
            <atom:updated>2022-05-03T21:17:22.984Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nbN27RdqN2KqpTZGCjWUAA.jpeg" /><figcaption>Think of a static website as if we were sitting at a sushi belt in a restaurant. Instead of waiting for the good pieces to come past use at our seat, we can choose precisely the sushi pieces we want right away, ready served. Photo by: <a href="https://unsplash.com/@kyleunderscorehead">https://unsplash.com/@kyleunderscorehead</a></figcaption></figure><p>Single-Page Applications (SPA’s, or dynamic) and server-based, also called Server Side Rendered (SSR) applications, are probably the most popular ways to create websites these days. But also Static Site Generation (SSG) has become very popular in the past years.</p><p>When we need a <em>fast</em>, <em>simple</em>, <em>secure</em>, and <em>cheap </em>website<em>, </em>our next project should be using Static Site Generation.</p><h3>Static vs. dynamic websites</h3><p>To begin with, we should clear up what the main differences between a static generated website and dynamic websites are:</p><p><strong>A static website</strong> is <em>pre-built (on the server) and fetched once on the client without a server</em>.</p><ul><li>Static-generated sites are just a bunch of HTML files. The site may be updated and re-build when publishing new content through a Content Delivery Network (CDN) or when pushing new features. With static site generation, websites become fast; they are easy to publish and secure! We will drill deeper into these benefits later on.</li></ul><p><strong>A dynamic website</strong> is when <em>files are changed on the server and fetched on the client on each change</em>.</p><ul><li>Dynamic sites consist of a backend with servers and databases. The site’s content changes dynamically and needs to interact with a database to generate the files “on the fly.” Also, the site needs to fetch the content every time someone revisits the site. Dynamic sites are harder to maintain and less reliable.</li></ul><h3>Benefits of Static Site Generation</h3><p>Dynamic and statically generated websites are suitable for different types of applications. Static Generation has unique features for creating a website with few dependencies, and suites better when meeting business goals is crucial.</p><p>We will look at <strong>eight</strong> benefits that SSG provide, whereas dynamic websites are not quite as good:</p><h4>No need for a backend developer</h4><p>We won’t need a backend developer to make an SSG website. Content Administrators and Writers can maintain a Content Management System that stores and have manageable content. Also, a Content Delivery Network (CDN) is a great place to upload our static files.</p><h4>Better reliability</h4><p>We won’t receive irritating error messages like “500 Internal Server Error.” on an SSG website. The only possible time we will get errors is when the hosting provider gets issues, which rarely happens. Besides that, our website will not have downtime or be unavailable. We will also not need to worry about dynamically scaling our servers or databases.</p><h4>Simplicity</h4><p>With Static Site Generation comes simplicity. They require no servers or databases. Some JavaScript frameworks, like React-based ones NextJS or GatsbyJS and SvelteJS, provide build-in support and help us generate, minify, and bundle static HTML files at build time. The static files can easily change or move from one hosting service to another.</p><h4>Performance</h4><p>Static Site Generation gives excellent performance and is fast. We won’t need to wait for many spinners [or skeletons] to tell the user that something is on the way and will replace it at some point.</p><p>Think of a static website as if we were sitting at a sushi belt in a restaurant. Instead of waiting for the good pieces to come past use at our seat, we can choose precisely the sushi pieces we want right away, ready served.</p><h4>Security</h4><p>We will have excellent security since we don’t need a database or servers running, and they are vulnerable to security breaches. Compilation of source code and content ahead of time (AoT) makes it impossible for hackers to access our databases, CMS, or servers. Since there are no servers involved, the site is also more resilient to DDoS attacks.</p><h4>Lower costs</h4><p>We may choose to upload our static content to services like Netlify, Vercel, Amazon S3, Google Cloud Platform, and Microsoft Azure; these services are also entirely free. Hosting static content is cheap and requires less bandwidth. And since our site will be less vulnerable to security breaches, we may use that left-over-money for other essential business goals instead of thinking of security monitoring.</p><h4>Improved SEO</h4><p>Dynamic sites can be complex when we want to optimize our website for search engines. And if it’s crucial for our site and content. The most common problems with dynamic sites are that these are fast at first page-load, but most critical content is fetched and displayed asynchronously.</p><p>We get well-optimized content for SEO with pre-rendered content and fast page load. Good SEO optimization will give a low or decreased “bounce rate,” which is the proportion of visitors leaving the website. It also improves search traffic, better lead generation, and customer engagement.</p><h4>Scalability</h4><p>Static Site Generation provides excellent scalability; we cannot always say the same with dynamic sites. So let’s take a scenario where we may have scalability issues with a dynamic site:</p><ul><li>We have a website that a few visitors typically use. At one point (maybe just a few minutes), the site can be used by thousands of users simultaneously. Maybe we’ve published something that has gone viral — such as news — or a DDoS attack. Such an event can be costly, grow rapidly in volume and take down our servers in the worst case. Such events can cause an unexpectedly large number of server requests and will potentially generate dynamic content for each of the thousands of unexpected users.</li></ul><p>Static content and SSG are different: The website is pre-generated, with styles and content. Users only need to download the page’s content that they are visiting.</p><h3>Conclusion</h3><p>We should use Static Site Generation when making a blog, landing page, newspaper, hotel booking service, or e-commerce store. On some occasions, we may even combine dynamic and static content, where our public pages as static pre-rendered content and internal or user-oriented pages are dynamic.</p><p>When running an online newspaper, combing dynamic and static content might be a good choice. The front pages can be of static content presented on the page to the users as soon as they enter, with main headlines and images, and videos can have a generated GIF instead of loading in a preview. Articles can then be fetched by an identifier (id) in the URL and rendered in a separate application or on a different route on the website that dynamically retrieves the content.</p><p>Static Site Generation should be considered over dynamic SPA’s if any of the abovementioned points are crucial for our organization, whether costs, user experience, or performance.</p><p>Thanks for reading!</p><p><em>Code foh shizzle</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5fb187d1ffe6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dfind-consulting/benefits-of-static-websites-5fb187d1ffe6">Benefits of Static Site Generation</a> was originally published in <a href="https://medium.com/dfind-consulting">Dfind Consulting</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ramda your JavaScript]]></title>
            <link>https://medium.com/compendium/ramda-your-javascript-e72bfaef01d5?source=rss-830a2ef44966------2</link>
            <guid isPermaLink="false">https://medium.com/p/e72bfaef01d5</guid>
            <category><![CDATA[skaperglede]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[teknologi]]></category>
            <category><![CDATA[kreativitet]]></category>
            <dc:creator><![CDATA[Marius Ibsen]]></dc:creator>
            <pubDate>Mon, 10 Aug 2020 19:47:50 GMT</pubDate>
            <atom:updated>2022-09-25T11:58:27.599Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fq-o56NAWwCeRVtLKwoPXA.png" /></figure><p>Nowadays, there is always something exciting to discover in the developer world: new frameworks, libraries, code styles, inspiring designs, methodologies, and a lot more. I’ve been most interested in <em>functional programming</em> in JavaScript in recent months.</p><h4>Introduction</h4><p>The functional programming paradigm is entirely new to me, but it has made me think less traditionally about writing code. I believe that writing [and thinking] in a <em>functional</em> way will make your code more readable; you will eventually have a more consistent language across developers in your team. It will be easier to debug and refactor your code later on. You will probably also write less code and make more useful stuff. Doing functional programming is different but also a lot of fun when you get used to it.</p><p>In this post, I want to show you some cool things that RamdaJs — which I will now call <em>Ramda</em> for simplicity and laziness — can do. First of all, it is worth knowing that Ramda is a JavaScript library that helps you write functional, concise, and reusable code. Ramda is declarative (rather than imperative, which is the most common method these days). So to get a better understanding of why Ramda is useful, we should have a basic knowledge of functional programming principles and then some examples with Ramda.</p><p><strong>We are going into the following topics:</strong></p><ul><li>Currying</li><li>Pure functions</li><li>Composition</li><li>Immutability</li><li>Example: The List of Notes</li></ul><h3>Currying</h3><p>Currying is a technique where we can “think of transforming” a function that takes many arguments to a more specific function that takes fewer arguments. With the help of currying, we can split a big and nested function into smaller functions. Then we remove complexity and make a function concise and reusable.</p><h4>Curried functions</h4><p>A curried function won’t do anything before it has received all the required arguments that it needs. It will take each argument <em>one at a time</em>.</p><p>Given that we have a function that takes three parameters, a curried version of the function will take one argument and return a function that takes the next argument, which then returns a function that takes the third argument.</p><p>A function with three parameters that sums the numbers provided for each function may we write as:</p><pre>// add = a =&gt; b =&gt; c =&gt; Number<br>const add = a =&gt; b =&gt; c =&gt; a + b + c;</pre><p>To make that function fully work, we need to apply all of its parameters. We can do this in several ways, and all the examples below are allowed:</p><pre>add(1, 2, 3) // 6<br>add(4)(1, 10) // 15<br>add(2, 3)(2) // 7<br>add(3)(2)(1) // 6</pre><pre>add(2)(3) // partially applied</pre><p>What makes Ramda great is that their functions are automatically curried, which allows us to quickly build up sequences of small and straightforward functions or old functions that we already have created.</p><h3>Pure functions</h3><p>A <em>pure function</em> is an essential concept in functional programming. By <em>pure</em>, we mean that a function should be without so-called “side effects.”</p><p>Some basic rules for pure functions are:</p><ul><li>It does not assign new values to outstanding variables, i.e., outside its own scope, between <strong>{</strong> and <strong>}</strong>.</li><li>It does not read or write to a database or do API calls.</li><li>It does not mutate incoming arguments. (This is a stringent rule, and it’s not always possible to prevent using side effects in our functions. But for the most part, all functions should be as clean as possible.)</li></ul><p>Sometimes, you may even want to nest functions within other functions that use variables from a parent function scope. In this case, you should consider splitting the function into smaller ones and instead pass values through them.</p><h3>Composition</h3><p><em>Composition</em> is when we take a <em>return</em> function and pass it as the parameter to another function. Take a look at the code below:</p><pre>const flip = x =&gt; x.split(&#39;&#39;).reverse().join(&#39;&#39;)<br>const exclaim = x =&gt; `${x}!`</pre><pre><strong>const flipAndShout = x =&gt; exclaim(flip(x))</strong></pre><pre>flipAndShout(&#39;dlroW olleH&#39;) // &quot;Hello, World!&quot;</pre><p>Here we call two functions where both do something to the value <em>x</em>. This code is hard to read. It would be even more challenging if we added many more functions to the <strong>flipAndShout</strong> variable.</p><p>The next example is a compose function:</p><pre>const compose = (f, g) =&gt; {<br>  return x =&gt; f(g(x))<br>}</pre><p>Arguments f and g are functions, and x is the value that runs through them. Here the function g will run first, then the function f, which will make a call flow from right to left. To get an idea of how to implement this, we can refactor the code from the previous example and use our compose function instead:</p><pre>const flip = x =&gt; x.split(&#39;&#39;).reverse().join(&#39;&#39;)<br>const exclaim = x =&gt; `${x}!`</pre><pre><strong>const flipAndShout = compose(exclaim, flip)</strong></pre><pre>flipAndShout(&#39;dlroW olleH&#39;) // &quot;Hello, World!&quot;</pre><p>This is much easier to read than a bunch of function calls. We can, just by taking a quick look, actually see what the <strong>flipAndShout</strong> function will return. Later we will look at some examples of Ramda’s composition functions.</p><h3>Immutability</h3><p>The concept of immutability and immutable data is also essential in functional programming.</p><p>Immutability means that existing data should not change. We initialize a variable with some value (string, array, number); it should not <em>change</em> data type (or be cast as) nor overwritten — not even object-properties or elements in an array. If existing data are changed, we may end up having some big problems when doing debugging, and the code may not be as readable if someone, at some point, needs to refactor it.</p><h3>May we do some Ramda now…?</h3><p>Yep.</p><p>Ramda is an excellent library for getting started on thinking functionally with JavaScript. Ramda provides a great toolbox with a lot of useful functionality and decent <a href="https://ramdajs.com/docs/">documentation</a>. If you’d like to try the functionality as we go, check out Ramda’s <a href="https://ramdajs.com/repl/">REPL</a>.</p><h4>Installation</h4><p>Ramda can be installed in several ways, via Yarn or NPM (but they also offer some <a href="https://ramdajs.com/">CDN’s on their website</a>):</p><pre>yarn add ramda</pre><pre>// or </pre><pre>npm install ramda</pre><h4>Usage</h4><p>require or import it into your project:</p><pre>const R = require(&#39;ramda&#39;)</pre><pre>// or</pre><pre>import R from &#39;ramda&#39;</pre><p>Or you can import each function if that suits you better. You then don’t need to prepend the R. for each function used:</p><pre>import { map, filter, prop } from &#39;ramda&#39;</pre><p>If you are using the <a href="https://ramdajs.com/repl/">REPL</a>, there’s no need to import anything. You can write the functions (or copy/paste directly from here) like they are already available and ready out of the box.</p><h3>Example: The List of Notes</h3><p>A common thing all developers will come to create someday is a list of notes. We add notes to our <em>list</em>, and when we’re finished with a note, we archive it.</p><p>We want a data set that contains both regular notes and reminders for such a list of notes. We’ll be using the following notesList array for our example. Objects with a valid (not null) “dueDate”-property are reminders while those without are regular notes:</p><pre>const notesList = [<br>  {<br>    title: &quot;Buy milk and bread&quot;,<br>    createdAt: &#39;2020-04-04&#39;,<br>    dueDate: null,<br>    archived: false,<br>  },<br>  {<br>    title: &quot;Pick up a package at the post office&quot;,<br>    createdAt: &#39;2020-04-04&#39;,<br>    dueDate: null,<br>    archived: false,<br>  },<br>  {<br>    title: &quot;Take a walk with Yoda&quot;,<br>    createdAt: &#39;2020-04-04&#39;,<br>    dueDate: null,<br>    archived: true,<br>  },<br>  {<br>    title: &quot;Read 15 minutes&quot;,<br>    createdAt: &#39;2020-03-07&#39;,<br>    dueDate: &#39;2020-03-08&#39;,<br>    archived: false,<br>  },<br>  {<br>    title: &quot;Do 30 minutes workout&quot;,<br>    createdAt: &#39;2020-03-01&#39;,<br>    dueDate: &#39;2020-03-04&#39;,<br>    archived: false,<br>  },<br>]</pre><h4>Filtering</h4><p>A typical action to do with this list is to filter out what we’ve already completed (in this case, “archived”). By using the build-in Array-methods, we can achieve what we want:</p><pre>const filterNotes = notesList.filter(note =&gt; !note.archived);</pre><p>With Ramda we can do the following:</p><pre>const filterNotes = R.filter(R.propEq(&#39;archived&#39;, false));</pre><p>Hmm, what happened here? We are not passing any parameters to the filterNotes function that uses the Ramda syntax. This is because the function is of <em>point-free-style.</em></p><p><em>Pointfree-style is also a functional programming style where the function definition (the function’s body) does not reference the function’s arguments. We can get a point-free-style by calling a function that returns a function, such as a curried function. Let us remind ourselves of the curried example earlier in this post:</em></p><pre>// add = a =&gt; b =&gt; c =&gt; Number<br>const add = a =&gt; b =&gt; c =&gt; a + b + c;</pre><p>Therefore we do not need to assign arguments to the function definition. Or said otherwise, we do not need to “tell” the Ramda function what data it needs.</p><p>We still need to call the filterNotes function with an argument to make it work, and the argument must be a list of objects, and the objects must contain at least an archived property.</p><h4>Sorting by property</h4><p>Now we have filtered out all the notes that are not archived. Let’s now sort the notes by their creation date. For this we can use the sortBy and prop functions from Ramda:</p><pre>const filterNotes = filter(propEq(&#39;archived&#39;, false));</pre><pre><strong>const sortByCreatedAt = sortBy(prop(‘createdAt’));<br>const filteredNotes = filterNotes(notesList);</strong></pre><pre><strong>sortByCreated(filteredNotes);</strong></pre><h4>Function composition</h4><p>The code above is not very readable, but how can we make it so? Earlier, we talked about composition. With function composition, we can build up pipelines of functions of other small functions. Ramda provides a couple of functions for doing function composition, and these are called pipe and compose.</p><p>Both functions take one or more arguments and return a function. pipe does <em>left-to-right</em> composition. It takes the first argument, passes the result to the next argument, and continues like this until the last argument. compose is a little different and applies arguments <em>right-to-left.</em></p><p>It doesn’t matter which of them you use, but go for what reads you best. I prefer to use compose in the examples as this is what my eyes handle best.</p><p>We can use compose on <strong><em>filterNotes</em></strong> and <strong><em>sortByCreatedAt</em></strong>:</p><pre>const filterNotes = filter(propEq(&#39;archived&#39;, false));</pre><pre><strong>const sortByCreatedAt = sortBy(prop(&#39;createdAt&#39;));</strong><br><strong>const sortNotes = compose(sortByCreatedAt, filterNotes);</strong></pre><pre>sortNotes(notesList);</pre><p>If we want to sort the notes in descending order and at the same time reuse code that we have already written. How can we achieve that? Ramda’s reverse function will come in handy here. reverse takes a list and returns it in reversed order:</p><pre>const filterNotes = filter(propEq(&#39;archived&#39;, false));</pre><pre><strong>const sortByCreatedAt = sortBy(prop(&#39;createdAt&#39;));</strong><br><strong>const sortByCreatedAtDescending = compose(reverse, sortByCreated);</strong></pre><pre>const sortNotes = compose(<strong>sortByCreatedAtDescending</strong>, filteredNotes);</pre><pre>sortNotes(notesList);</pre><h4>Group by category</h4><p>Ramda has a function called <em>groupBy</em>, which splits a list into sub-lists and then stores the result in an object.</p><p>For our example, we can pass a function that makes a conditional statement for the “dueDate” property in each object and then return which “key” a note should be grouped within.</p><p>Our function can be written like this:</p><pre>const groupByType = groupBy(n =&gt; n.duedate ? &#39;reminders&#39; : &#39;notes&#39;)</pre><p>And implement it with the rest of the code:</p><pre>const filterNotes = filter(propEq(&#39;archived&#39;, false));<br>const sortByCreatedAt = sortBy(prop(&#39;createdAt&#39;));</pre><pre><strong>const groupByType = groupBy(n =&gt; n.dueDate ? &#39;reminders&#39; : &#39;notes&#39;)</strong></pre><pre><strong>const filterByType = compose(groupByType, sortByCreatedAt);</strong><br>const sortedNotes = compose(<br>      <strong>filterByType</strong>,<br>      filterNotes<br>    );</pre><pre>sortedNotes(notesList)</pre><p>Our code looks excellent. Now we have all the notes and reminders grouped (each type as object keys), and we get this:</p><pre>{<br>    notes: [<br>        {<br>            archived: false,<br>            createdAt: &quot;2020-04-04&quot;,<br>            dueDate: null,<br>            title: &quot;Buy milk and bread&quot;<br>        },<br>        {<br>            archived: false,<br>            createdAt: &quot;2020-04-04&quot;,<br>            dueDate: null,<br>            title: &quot;Pick up a package at the post office&quot;<br>        }<br>    ],<br>    reminders: [<br>        {<br>            archived: false,<br>            createdAt: &quot;2020-03-01&quot;,<br>            dueDate: &quot;2020-03-04&quot;,<br>            title: &quot;Do 30 minutes workout&quot;<br>        },<br>        {<br>            archived: false,<br>            createdAt: &quot;2020-03-07&quot;,<br>            dueDate: &quot;2020-03-08&quot;,<br>            title: &quot;Read 15 minutes&quot;<br>        }<br>    ]<br>}</pre><p><a href="https://ramdajs.com/repl/?v=0.27.0#?const%20notesList%20%3D%20%5B%0A%20%20%7B%0A%20%20%20%20title%3A%20%22Buy%20milk%20and%20bread%22%2C%0A%20%20%20%20createdAt%3A%20%272020-04-04%27%2C%0A%20%20%20%20dueDate%3A%20null%2C%0A%20%20%20%20archived%3A%20false%2C%0A%20%20%7D%2C%0A%20%20%7B%0A%20%20%20%20title%3A%20%22Pick%20up%20package%20at%20mail%20office%22%2C%0A%20%20%20%20createdAt%3A%20%272020-04-04%27%2C%0A%20%20%20%20dueDate%3A%20null%2C%0A%20%20%20%20archived%3A%20false%2C%0A%20%20%7D%2C%0A%20%20%7B%0A%20%20%20%20title%3A%20%22Take%20a%20walk%20with%20Yoda%22%2C%0A%20%20%20%20createdAt%3A%20%272020-04-04%27%2C%0A%20%20%20%20dueDate%3A%20null%2C%0A%20%20%20%20archived%3A%20true%2C%0A%20%20%7D%2C%0A%20%20%7B%0A%20%20%20%20title%3A%20%22Read%2015%20minutes%22%2C%0A%20%20%20%20createdAt%3A%20%272020-03-07%27%2C%0A%20%20%20%20dueDate%3A%20%272020-03-08%27%2C%0A%20%20%20%20archived%3A%20false%2C%0A%20%20%7D%2C%0A%20%20%7B%0A%20%20%20%20title%3A%20%22Do%2030%20minutes%20workout%22%2C%0A%20%20%20%20createdAt%3A%20%272020-03-01%27%2C%0A%20%20%20%20dueDate%3A%20%272020-03-04%27%2C%0A%20%20%20%20archived%3A%20false%2C%0A%20%20%7D%2C%0A%5D%0A%0Aconst%20filterNotes%20%3D%20filter%28whereEq%28%7B%20archived%3A%20false%20%7D%29%29%3B%0Aconst%20sortByCreatedAt%20%3D%20sortBy%28prop%28%27createdAt%27%29%29%3B%0Aconst%20groupByType%20%3D%20groupBy%28n%20%3D%3E%20n.dueDate%20%3F%20%27reminders%27%20%3A%20%27notes%27%29%0Aconst%20filterByType%20%3D%20compose%28groupByType%2C%20sortByCreatedAt%29%3B%0Aconst%20sortedNotes%20%3D%20compose%28%0A%20%20%20%20%20%20filterByType%2C%0A%20%20%20%20%20%20filterNotes%0A%20%20%20%20%29%3B%0AsortedNotes%28notesList%29">See result in Ramda REPL</a></p><h4>Finishing up</h4><p>Now, some of the object properties in our notesList may not always be that necessary.</p><p>We could have a user interface where we only need some of the properties to display them visually (and the rest is left unused). These properties we can consider as <em>important</em> information. <a href="https://ramdajs.com/docs/#project">project</a> is a Ramda function that is similar to SQL select and can select the (important) properties that we want from each object (it is also a combination of Ramda pick and map):</p><pre>const importantFields = project([&#39;title&#39;, &#39;createdAt&#39;<strong>, </strong>&#39;dueDate&#39;]);</pre><p>Let’s implement this with the rest of the code:</p><pre>const filterNotes = filter(propEq(&#39;archived&#39;, false));<br>const sortByCreatedAt = sortBy(prop(&#39;createdAt&#39;));<br>const sortByCreatedAtDescending = compose(reverse, sortByCreatedAt);<br>const groupByType = groupBy(n =&gt; n.dueDate ? &#39;reminders&#39; : &#39;notes&#39;)</pre><pre><strong>const importantFields = project([&#39;title&#39;, &#39;createdAt&#39;, &#39;dueDate&#39;]);</strong></pre><pre>const filterByType = compose(groupByType, sortByCreatedAt)<br>const sortedNotes = compose(<br>      <strong>importantFields</strong>,<br>      filterByType,<br>      filterNotes<br>    )<br>sortedNotes(notesList)</pre><p><a href="https://ramdajs.com/repl/?v=0.27.0#?const%20notesList%20%3D%20%5B%0A%20%20%7B%0A%20%20%20%20title%3A%20%22Buy%20milk%20and%20bread%22%2C%0A%20%20%20%20createdAt%3A%20%272020-04-04%27%2C%0A%20%20%20%20dueDate%3A%20null%2C%0A%20%20%20%20archived%3A%20false%2C%0A%20%20%7D%2C%0A%20%20%7B%0A%20%20%20%20title%3A%20%22Pick%20up%20package%20at%20mail%20office%22%2C%0A%20%20%20%20createdAt%3A%20%272020-04-04%27%2C%0A%20%20%20%20dueDate%3A%20null%2C%0A%20%20%20%20archived%3A%20false%2C%0A%20%20%7D%2C%0A%20%20%7B%0A%20%20%20%20title%3A%20%22Take%20a%20walk%20with%20Yoda%22%2C%0A%20%20%20%20createdAt%3A%20%272020-04-04%27%2C%0A%20%20%20%20dueDate%3A%20null%2C%0A%20%20%20%20archived%3A%20true%2C%0A%20%20%7D%2C%0A%20%20%7B%0A%20%20%20%20title%3A%20%22Read%2015%20minutes%22%2C%0A%20%20%20%20createdAt%3A%20%272020-03-07%27%2C%0A%20%20%20%20dueDate%3A%20%272020-03-08%27%2C%0A%20%20%20%20archived%3A%20false%2C%0A%20%20%7D%2C%0A%20%20%7B%0A%20%20%20%20title%3A%20%22Do%2030%20minutes%20workout%22%2C%0A%20%20%20%20createdAt%3A%20%272020-03-01%27%2C%0A%20%20%20%20dueDate%3A%20%272020-03-04%27%2C%0A%20%20%20%20archived%3A%20false%2C%0A%20%20%7D%2C%0A%5D%0A%0Aconst%20filterNotes%20%3D%20filter%28R.whereEq%28%7B%20archived%3A%20false%20%7D%29%29%3B%0Aconst%20sortByCreatedAt%20%3D%20sortBy%28prop%28%27createdAt%27%29%29%3B%0Aconst%20sortByCreatedAtDescending%20%3D%20compose%28reverse%2C%20sortByCreatedAt%29%3B%0Aconst%20groupByType%20%3D%20groupBy%28n%20%3D%3E%20n.dueDate%20%3F%20%27reminders%27%20%3A%20%27notes%27%29%0Aconst%20importantFields%20%3D%20project%28%5B%27title%27%2C%20%27createdAt%27%2C%20%27dueDate%27%5D%29%3B%0Aconst%20filterByType%20%3D%20compose%28groupByType%2C%20sortByCreatedAt%29%0Aconst%20sortedNotes%20%3D%20compose%28%0A%20%20%20%20%20%20map%28importantFields%29%2C%0A%20%20%20%20%20%20filterByType%2C%0A%20%20%20%20%20%20filterNotes%0A%20%20%20%20%29%0AsortedNotes%28notesList%29">See final result in REPL</a></p><p>Now we have an object containing two arrays, sorted by created date and active status; how great isn’t that? As our final result, see how clean it is, and we got just the data that we need:</p><pre>{<br>    notes: [<br>        {<br>            createdAt: &quot;2020-04-04&quot;,<br>            dueDate: null,<br>            title: &quot;Buy milk and bread&quot;<br>        },<br>        {<br>            createdAt: &quot;2020-04-04&quot;,<br>            dueDate: null,<br>            title: &quot;Pick up package at mail office&quot;<br>        }<br>    ],<br>    reminders: [<br>        {<br>            createdAt: &quot;2020-03-01&quot;,<br>            dueDate: &quot;2020-03-04&quot;,<br>            title: &quot;Do 30 minutes workout&quot;<br>        },<br>        {<br>            createdAt: &quot;2020-03-07&quot;,<br>            dueDate: &quot;2020-03-08&quot;,<br>            title: &quot;Read 15 minutes&quot;<br>        }<br>    ]<br>}</pre><p>Thanks for reading!</p><p><em>Code foh shizzle</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e72bfaef01d5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/compendium/ramda-your-javascript-e72bfaef01d5">Ramda your JavaScript</a> was originally published in <a href="https://medium.com/compendium">Compendium</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>