▲ 516 ▼ You can pry pattern matching from my cold dead hands (sopuli.xyz) submitted 8 months ago by flamingo_pinyata@sopuli.xyz to c/programmer_humor@programming.dev 222 comments fedilink hide all child comments
[–] SaharaMaleikuhm@feddit.org 6 points 8 months ago (2 children) Skill issue. Once you learn them they are quite fun. permalink fedilink source parent hideshow 4 child comments replies: [–] unit327@lemmy.zip 10 points 8 months ago The concept of a list comprehenshion is sinple but syntax is awful, as if Yoda was writing a for loop. "x for x in y it is, hmm yes". permalink fedilink source parent [–] tyler@programming.dev 2 points 8 months ago I'm not saying I don't understand them. I'm saying the syntax is terrible. Compare it to Ruby (or any other modern language) and it's abundantly clear. python (uses syntax not available in any other top 25 language) print([j**2 for j in [2, 3, 4, 5]]) # => [4, 9, 16, 25] ruby (normal chain syntax with map) puts [2, 3, 4, 5].map{|j| j**2} even kotlin is more readable, even though you have to convert to a double and back kotlin val list = listOf(1,2,3,4) println(list.map{it.toDouble().pow(2.0).toInt()}) For nested cases it's even more apparent: python digits = [1, 2, 3] chars = ['a', 'b', 'c'] print([str(d)+ch for d in digits for ch in chars if d >= 2 if ch == 'a']) # => ['2a', '3a'] ruby digits = [1, 2, 3] chars = ['a', 'b', 'c'] digits.product(chars).select{ |d, ch| d >= 2 && ch == 'a' }.map(&:join) kotlin val digits = listOf(1, 2, 3) val chars = listOf('a', 'b', 'c') println(digits.flatMap { d -> chars.filter { ch -> d >= 2 && ch == 'a' }.map { ch -> "${d}${ch}" }}) just from a base level, you have to read the middle of the comprehension first, then the end, then the beginning. It's a completely backwards way to write and read code. unlike other languages that use a 'functional' approach, where it's chained methods or pipes, etc. Even Elixir, which does have list comprehensions, reads and writes in the proper order: elixir for x <- 0..100, x * x > 3, do: x * 2 permalink fedilink source parent
[–] unit327@lemmy.zip 10 points 8 months ago The concept of a list comprehenshion is sinple but syntax is awful, as if Yoda was writing a for loop. "x for x in y it is, hmm yes". permalink fedilink source parent
[–] tyler@programming.dev 2 points 8 months ago I'm not saying I don't understand them. I'm saying the syntax is terrible. Compare it to Ruby (or any other modern language) and it's abundantly clear. python (uses syntax not available in any other top 25 language) print([j**2 for j in [2, 3, 4, 5]]) # => [4, 9, 16, 25] ruby (normal chain syntax with map) puts [2, 3, 4, 5].map{|j| j**2} even kotlin is more readable, even though you have to convert to a double and back kotlin val list = listOf(1,2,3,4) println(list.map{it.toDouble().pow(2.0).toInt()}) For nested cases it's even more apparent: python digits = [1, 2, 3] chars = ['a', 'b', 'c'] print([str(d)+ch for d in digits for ch in chars if d >= 2 if ch == 'a']) # => ['2a', '3a'] ruby digits = [1, 2, 3] chars = ['a', 'b', 'c'] digits.product(chars).select{ |d, ch| d >= 2 && ch == 'a' }.map(&:join) kotlin val digits = listOf(1, 2, 3) val chars = listOf('a', 'b', 'c') println(digits.flatMap { d -> chars.filter { ch -> d >= 2 && ch == 'a' }.map { ch -> "${d}${ch}" }}) just from a base level, you have to read the middle of the comprehension first, then the end, then the beginning. It's a completely backwards way to write and read code. unlike other languages that use a 'functional' approach, where it's chained methods or pipes, etc. Even Elixir, which does have list comprehensions, reads and writes in the proper order: elixir for x <- 0..100, x * x > 3, do: x * 2 permalink fedilink source parent