13 ms·
Cursed Elixir
- adenozine 6y agoThanks, I hate it. Jokes aside, there is something fascinating about programming languages being abused like this. Like tongue twisters and word games, ain't these basically the same thing in a programming language instead of a spoken language?
- daniellarusso 6y agoContests: https://www.ioccc.org/ https://www.ioccc.org/
- adenozine 6y agoYeah, that's kind of a similar thing! I guess riddles of obscurity are kinda like using overly esoteric words in conversation. Does that seem like the right parallel? When I see something like the elixir with too many pipes, I think of Dr Seuss rhymes, but when I see obfuscated code, it's kinda like gibberish.
- dnautics 6y agoI think it's fascinating because it exposes some deeper facts about how the language works under the hood
- adenozine 6y agoInteresting perspective! I definitely didn't know about |> def I suppose ruby has dynamic def as well though.
- tel 6y agoI don't think it's dynamic, just macros. a |> foo() |> def do ... end just gets macroexpanded to foo(a) |> def do ... end and then def foo(a) do ... end.
- dnautics 6y agoI didn't know about |> def, but at the same time I'm totally not surprised (you should never use it though). |> case do is a fun one that I actually do use often.
- rkangel 6y agoI've almost written "|> case do" several times and then in each case have decided that it makes sense to a separate private function (with function head matching for the different cases).
- mercer 6y agoI've found "|> case do" to feel 'right' at times when it's at the end of the pipeline.
- higerordermap 6y agoCode golfing?
- karolkozub 6y agoI was raised on programming contests and it took me many years to realize that clever code doesn't equate good code. In the vast majority of cases readability is more important than cleverness, performance, abstraction, and adhering to imaginary rules. The best measure for the quality of the codebase is whether at a glance you can understand what's going on.
- hprotagonist 6y ago> The best measure for the quality of the codebase is whether at a glance you can understand what's going on. ... in 6 months when you’ve forgotten 80% of the context.
- dnautics 6y agoElixir is pretty good at this. I've found it really easy to do a (useful) drive-by pr on someone's open source code, for example, so that's with almost no context whatsoever. Nobody writes code like the op though (I'm pretty sure it's satire)
- imperfectcats 6y agoI think having a tool to standardise formatting is huge, and a lot of what makes Elixir code easy to read is mix format. That and the fact most of the community started out with similar ideas on good code, so there was less bikeshedding around formatting.
- dnautics 6y agoEh, I think there are more important things, like if you pass a variable to a remote function, it doesn't ever mutate underneath you when you try to use it later.
- mercer 6y agoAgreed. I maintain a whole bunch of codebases, many of which are a few years old, and it's so much easier to dust of an Elixir project (pre-formatter) than, say, picking up on a Wordpress or Drupal project.
- quda 6y agoVery poor example of 'functionalization'. The final result might not look like Ruby, but it looks like a hot mess - undecipherable.
- burke 6y ago> Who's going to say this looks like Ruby now? Challenge accepted. Here's how far I've got so far: $l=[nil,nil,nil,nil] TracePoint.trace(:call) do |tp| $l << tp.self $l.shift end class Lol < BasicObject def initialize(f) @f = f end def method_missing(m, *a) # puts $l[0].inspect $l[0].send(m, @f, *a) end end class BasicObject def ►(&blk) ::Lol.new(self).instance_exec(&blk) end end module FooBar def self.foo(a) if a < 0 a.► { bar -1 } else a.► { bar 1 } end end def self.bar(a, b) (a*b).► { puts } end end FooBar.foo(4)
- stopachka 6y agoMasterful! Great job burke!
- sergeykish 6y agoFooBar = Module.new def FooBar.foo(a) a < 0 ? bar(a, -1) : bar(a, 1) end def FooBar.bar(a, b) self.puts [a, b].reduce &:* end
- mikl 6y agoWow, that is hideous. Well done, sir.
- jamil7 6y agoYes, it gave me a progressively more uncomfortable feeling as I continued to read it.
- rmetzler 6y agoIf you used guards instead of the if, wouldn’t it be look less like Ruby while it would have the same or even better readability?
- conradfr 6y agoIndeed but it depends if those functions are used elsewhere, maybe they don't have to know about that if rule.
- Dirlewanger 6y agoI think I understand what they mean now when you're given "enough rope to hang yourself"
- jlouis 6y agoThis is fun, because it shows just how pervasive function application is in programming. You can build whole programming languages on just function application (which is what the Lambda calculus is about).
- transfire 6y ago> a |> foo() |> def do I find this part curious. How does Elixir know that a and foo aren't references/calls, before reaching def? Does Elixir work |> chains backwards?