6 ms·
I've recently jumped into Erlang, and have come to some of the same conclusions. I read Armstrong's Erlang book, and thought 'that seems cool' and didn't at all
by sofuture 16y ago
I've recently jumped into Erlang, and have come to some of the same conclusions. I read Armstrong's Erlang book, and thought 'that seems cool' and didn't at all grok what was going on beyond the superficial. Then a few months later, just sat down and started solving Project Euler problems. At first it was strange and foreign and I was mad variables were immutable. A day later and it just clicked, I'd never had that much fun writing code.
The FP paradigm is (to me, even after 15 years of imperative programming) so much more natural for development, since you're able to sanely start attacking the problem directly -- instead of architecting a big-picture solution up front that's probably wrong anyway because you've ignored some detail you haven't yet discovered.
Building things with actions instead of objects just makes much more sense. Reuse comes much more naturally, and doesn't seem as contrived as a lot of OOP reuse seems. I've noticed that working my FP muscles out has made me a much better imperative programmer -- I write a lot more clever and effective code (not clever like 'tee-hee-no-one-will-ever-figure-this-out'!).
- jacquesm 16y agoFor me one of the real eye openers was that I'd gotten to the end of a fairly long book on FP without seeing a single assignment of a value to a variable.
- rgoddard 16y agoI have just finished the first iteration of a web app written in clojure and in the several hundred lines of code, I have a single variable which changes state.
- jacquesm 16y agoNeat! Did you use a templating system? And if so which one?
- die_sekte 16y agoThe usual solution for that would be hiccup, with a few custom functions.
- runevault 16y agoDepends, Enlive is seeing at least some use as well (the web app I built for personal use has enlive handling the HTML as well).
- rgoddard 16y agoI am using hiccup for generating the html, compojure and ring for routing and request/response handling, jetty as the webserver and postgresql as the database
- jacquesm 16y agoDid you cook up your own authentication or is that provided by one of those?
- rgoddard 16y agoAs of now I am just using my own. The user can create an account with username/password. When they login, it will associate the user with the session object. Session management is handled by ring, although the session data resides in memory only. I have a function which wraps around the routes which require the user to be logged in and checks the session to make sure the user is not nil.
- mattyb 16y agoWhich book?
- jacquesm 16y agoThe Little Schemer.
- WilliamLP 16y agoOne thing that raises my eyebrows is how much functional programmers talk about Project Euler problems. The actual programming for solving these problems is in fact extremely trivial. They require some mathematical insight, especially after the first one hundred or so, and you need to do some external research on Pell's Equation to avoid getting stuck, and you need a fraction library if your language doesn't have it built in. But am I wrong in thinking that these kind of problems are almost no test or strain for your actual programming at all?
- nudge 16y agoNo mystery. Project Euler is a useful set of problems to tackle when learning a new language. It's not 'Wahoo with functional programming I can finally get past Euler 15'; it's 'Wow after a bunch of these Euler problems I think I am finally starting to get functional programming'.
- sofuture 16y agoThey're an absolutely fantastic way to start 'getting' any language. They're small, discrete, and varied tasks that require you to build different types of operations and structures. Sure, they're not at all reflective of 'real programming' nor are they necessarily particularly challenging, programming wise. I'd rather cut my teeth in a new language on the first 50 or so PE problems, than take on a bigger, less defined, or more domain limited task. I'm conversant in Python and Erlang because of PE problems entirely. They've enabled me to start actual projects in both languages.
- WilliamLP 16y ago> varied tasks That's where I'd argue. It would be like saying you're an all around gamer when you play only chess but with different openings every time. Varied simple tasks would be doing some Euler problems, doing some basic algorithms (Dijkstra's with Heap, A* pathfinder on a 2d map, etc... TopCoder problems are great for this), write a Mandelbrot zoomer, Conway's Life app with position setup and step-through and save/load, write a Tetris clone, write a basic HTML form builder, write a blogging engine, write a multi-user chat room server, write a simple side-scrolling shooter game, write a basic Roguelike game, write a simple text adventure. Things like this can all be afternoon projects. Every time I read someone claiming that Project Euler is for developing general-purpose programming, I roll my eyes more than a little.
- davidw 16y agoI've used Erlang for a while, although sporadically. Honestly, I think I can do more with less code in Ruby, though. Erlang's great for the things it's good at, but brevity and clarity are really things I think are critical. Here's a small example I bumped into the other day, providing a default value if a hash value isn't present: foo[:bar] || "beebop" vs case (catch dict:fetch(bar, Foo)) of {'EXIT', _} -> "beebop"; Val -> Val end (or something close, there might be a typo)
- sofuture 16y agoSo wrap it in a function default(Dict, Key, Default) -> case dict:is_key(Key, Dict) of true -> dict:fetch(Key, Dict); _ -> Default end.
- jrockway 16y agoDunno about Erlang, but in Haskell, you can actually call this function ||: import Prelude hiding ((||)) import qualified Data.Map as M import Data.Maybe (||) = flip fromMaybe main = print $ result || "OH NOES!" where result = M.lookup "baz" map map = M.fromList [("foo", "bar"), ("bar", "baz")] ghci> main "OH NOES!" With some typeclass magic, you can even make this work for arbitrary types. But don't waste your time with this, since it's already built in as `mplus`: ghci> Nothing `mplus` Just 42 Just 42 ghci> Left "OH NOES" `mplus` Right "it worked" Right "it worked"
- davidw 16y agoBelieve it or not, I actually had figured that out. The point was about the language in general, its verbosity, and the ability to string things together.
- deleted 16y ago[deleted]
- joshhart 16y agoThis is built into the Scala API - foo.getOrElse(bar, "beebop") Stuff like this should be built into the standard language.
- Nycto 16y agoThank you for the reference to Project Euler. I'm learning Scala right now and it gave me just the right sized challenges for testing my knowledge. They're big enough to take time and thought, but small enough that you can solve them within the CLI interpreter.