Sigma@sigmasternchen@comfy.social
Counting for ~~Dummies~~ Programmers:펼치기

Imperative:

for(let i = 0; i < 10; ++i) {
   console.log(i);
}

Declarative:

const range = (from, to) => [...Array(to - from).keys().map(i => i + from)];
range(0, 10).forEach(i => console.log(i));

Recursion:

const count = (from, limit) => {
    console.log(from);
    if (limit > 1) count(from + 1, limit -1);
};
count(0, 10);

???

((f,l)=>
    (f=>(g=>f(h=>g(g)(h)))(g=>f(h=>g(g)(h))))(
        c=>([f,l])=>console.log(f)??l>1?c([f+1,l-1]):null
    )([f,l])
)(0, 10)
❤4
1 1 4
ελΥ.𐤍@elyn@tech.lgbt
re: Counting for ~~Dummies~~ Programmers:펼치기

@sigmasternchen definitely, yeah!! I'd say my "first love", so to say, is pure mathematics, but I went into studying computer science cuz it felt adjacent while having the potential for remote work. And then as I went into it, I've come to actually get into it, especially functional and declarative patterns on account of them feeling truer to the underlying mathematical structures that motivate the code

Sigma@sigmasternchen@comfy.social
@elyn@tech.lgbt 님에게 답글
re: Counting for ~~Dummies~~ Programmers:펼치기
@elyn@tech.lgbt It's fascinating how different people approach this stuff. ^^ I think functional programming is super interesting and useful, but when it comes down to actually implementing software, more often than not I just fall back to imperative (or object-oriented) styles. I think it might be because my background is actually electronics and computer engineering, and imperative programming is closer to how the hardware works. ^^
ελΥ.𐤍@elyn@tech.lgbt
re: Counting for ~~Dummies~~ Programmers:펼치기

@sigmasternchen I'm actually coming to learn that more viscerally this semester in my digital systems engineering lab! I definitely also tend to reach towards more imperative approaches by default since that's what all my intro courses taught, but I go out of my way to learn and use any language features that provide functional approaches what I can

1 1

불러오는 중…