Fork me on GitHub
#beginners
<
2017-02-17
>
Drew Verlee02:02:15

I just heard an interview where Bob Martin said: > Object Oriented languages are a discipline around not having pointers to functions. I know this isnโ€™t the perfect channel for this question, but can anyone explain what he means? I have a guess, but i might be wrong.

lepistane17:02:37

are there any guidelines about posting questions here?

lepistane17:02:38

I am reading Web Dev with Clj (book) and after second chapter i got but which i cant seem to fix alone.

lepistane17:02:03

this is the code

lepistane17:02:05

(defroutes auth-routes (GET "/register" [] (registration-page)) (POST "/register" [id pass pass1] (handle-registration)) (GET "/login" [] (login-page)) (POST "/login" [id pass] (handle-login id pass)) (GET "/logout" [] (layout/common (form-to [:post "/layout"] (submit-button "Logout")))) (POST "/logout" [] (session/clear!) (redirect "/")))

lepistane17:02:46

(defn handle-registration [id pass pass1] (rule (= pass pass1) [:pass "password was not retyped correctly"]) (if (errors? :pass) (registration-page) (do (db/add-user-record {:id id :pass (crypt/encrypt pass)}) (redirect "/login"))))

lepistane17:02:31

i get arrity exception and i saw request in browser it does send id, pass and pass1

lepistane17:02:50

so problem is on server side but i am not sure what to do

rootkat17:02:44

which section of the book is that code from?

rootkat17:02:03

it seems like they don't get into auth until chapter 8 during the picture gallery app

lepistane17:02:10

second chapter

lepistane17:02:25

you do in second you work with session registartion and login

rootkat17:02:39

let me take a look, it's been a while since I worked through that book

lepistane17:02:57

would my code be of any help?

rootkat17:02:31

are you using the first edition of that book by any chance?

lepistane17:02:41

Yes it seems so. Little bonsai Green tree on the cover

rootkat17:02:57

oh, ok, they changed a bunch of stuff in the second edition

lepistane17:02:11

oh! i didnt know that. should i buy second edition then?

rootkat17:02:14

well, not necessarily, as long as you're using the correct versions of the libraries the code examples should still work.

rootkat17:02:26

however, if you're pulling the latest versions you might run into problems

lepistane17:02:45

i was strictly following the book it doesn't matter i will get second edition now

rootkat17:02:23

if nothing else you'll be getting the most up to date info

sveri17:02:27

@lepistane ArityException means that you are calling a function with the wrong number of arguments. Look here:

(POST "/register" [id pass pass1]
        (handle-registration))
...

(defn handle-registration [id pass pass1]
You have a function handle-registration that takes 3 arguments, but when calling the function you call it with 0 arguments.

lepistane17:02:19

OMG i cant belive i missed THIS!!! sorry to bother you. omggg.....

sveri17:02:44

@lepistane np just keep on bothering, this is what the beginners channel is there for ๐Ÿ™‚

jeffh-fp19:02:24

I can't find the link -- anyone recall a github project that was a TDD ClojureScript tutorial for a simple web app?

jeffh-fp19:02:54

I saw it recently and it looked cool and of course I didn't star/bookmark/readlater/fave/like/etc it

lepistane19:02:38

@sveri i fixed it but it still breaks Wrong number of args (0) passed to: auth/handle-registration

lepistane19:02:58

i restarted server, project, saved 10times,evalutated

sveri19:02:15

show us your fix then ๐Ÿ™‚

lepistane19:02:40

(defroutes auth-routes (GET "/register" [] (registration-page)) (POST "/register" [id pass pass1] (handle-registration id pass pass1)) (GET "/login" [] (login-page)) (POST "/login" [id pass] (handle-login id pass)) (GET "/logout" [] (layout/common (form-to [:post "/layout"] (submit-button "Logout")))) (POST "/logout" [] (session/clear!) (redirect "/")))

sveri19:02:52

if you post larger code snippets could you click the plus button to the left side of the input box please and then "code or text snippet". Also it seems like some code is missing.

jeffh-fp19:02:27

also consider using or `` for code

lepistane19:02:12

i understand sorry. i am new to slack. '''(defroutes auth-routes (GET "/register" [] (registration-page)) (POST "/register" [id pass pass1] (handle-registration id pass pass1)) (GET "/login" [] (login-page)) (POST "/login" [id pass] (handle-login id pass)) (GET "/logout" [] (layout/common (form-to [:post "/layout"] (submit-button "Logout")))) (POST "/logout" [] (session/clear!) (redirect "/"))) ''' is this better

sveri19:02:54

For large ones use the snippet, for small ones use `

sveri19:02:00

open and ending

sveri19:02:21

Also please post the functions that are being called, now I can only see the routes, but not the function definitions

lepistane19:02:05

i am either mentally challenged or something weird is happening it just worked

lepistane19:02:21

and i did nothing

lepistane19:02:55

btw what are situations where i have to restart server? everytime i update routes?

sveri19:02:44

This is a common occurring even with years of experience. That weird thing that is happening is just something you dont understand. In former times they called that weird thing god. Today people try to figure out what exactly went wrong or what changed ๐Ÿ˜„

sveri19:02:17

Depends on your setup if you have to restart the REPL, the server or nothing.

lepistane19:02:50

i am using emacs setup from Brave and True i run cider-jack-in (that starts nrepl) and i start server from there

timgilbert19:02:48

It depends on how your ring server is set up, but a lot of exmple code uses the ring-devel middleware, which will check to see if your code has changed and reload some namespaces if it has

timgilbert19:02:27

From personal experience I've found compojure defroutes stuff to be a little squirrelly with reloading though

timgilbert19:02:50

If you want to be certain, stopping and restarting your server if the best way to go

sveri19:02:54

Exactly. I had to use components and its restart functions to notify my repl of changed routes.

sveri19:02:47

Basically they just restart the server with the new routes, which still happens in ms time compared to a REPL restart, but that maybe goes to far for the beginning, so yes, restart the server for changed routes.

lepistane19:02:41

i understand. thank you a lot for taking time to help me. cheers!