Factor & shit, I am that naive sucker
March 14th, 2008Factor gets a lot of bashing at reddit. That is not that bad because traction always produces more energy and output than a soapy you are OK, I am OK, we are all OK stuff.
Few days back certain Factor non-fan amongst many other things wrote:
Because such Forth-like untyped languages have been around for decades and I was using them around 1990. Adapting the concept to 2008 may be fun for you and help you suck in a few naive developers but it doesn’t make it a serious platform; read up a little
While people on factor’s irc channel look highly educated programmers to me I recognised myself in this. Not that I am proud, but reality is I am sort of naive developer and I did get sucked into Factor. I am not formally educated as a programmer. I am more like the guy who once jumped into the river and managed not to sink, and then just stayed there, gradually improving his swimming, but never took time to learn the official butterfly stroke because he was too busy catching the fish.
Well I am “naive developer” in some way but I am also very pragmatic because the “useful working maintainable output” vs. the “sh*t that went into making it” is the only thing that matters to me at the end. I don’t code to learn, I learn to code.
And that’s why I now think that Factor will be my web-dev tool? Because I have tested and got very good results with 3 sides of web-development so far:
As my first Factor lines of code I tried to see how I could extract some data out of text. This simple and small vocab is what I came up with, and was amazed by cleanness and obviousness. So I see that making nice vocabularies that will help me parse strings will reall NOT be a problem with factor.
"i:1;name:Jon;age:3;surname:Wu;;i:2;name:Jill;age:9;surname:Huan;;"
"i:2" cut-to "name:" cut-off ";" snatch-to
"surname:" cut-off ";" get-to .s
! "Jill"
! "Huan"
So factor can read, but can it generate? Next, I wanted to se how I can generate SQL, this came out so far:
: get-users ( -- )
SELECT*
"users" FROM
"enabled = 1" WHERE
"username" ORDER get-rows ;
get-users
! SELECT * FROM users
! WHERE enabled = 1 ORDER BY username ;
: get-users-of-group+ ( orderby group fields -- )
SELECT
"users" FROM
swap "enabled = 1 AND group = ##" ##1' WHERE
swap ORDER ;
"email" 51 "email, username" get-users-of-group+
! SELECT email, username FROM users
! WHERE enabled = 1 AND group = 51 ORDER BY email ;
: change-email ( id email -- )
"users" UPDATE
"email = ##" ##1' SET
swap WHERE-id exec ;
123 "j@a.com" change-email
! UPDATE users SET email = 'j@a.com'
! WHERE id = 123 ;
Then I tried to make the XHTML forms generating vocabulary:
: show_user-form ( -- )
"post" "./user" start-form
"your info" start-fieldset
"Email" label (*) endlbl
"email" "" "class='big'" text-input endrow
"Name" label endlbl
"name" "" "size='12'" text-input endrow
no-label endlbl
"action_add-user" "Save" "" submit-input endrow
end-fieldset
end-form show! ;
The code creates the first form on this page.
Any part of my web-dev toolkit I tried to create in Factor so far was better looking than the ones I had developed in other languages. That’s why I will continue with Factor. I know and used only the “primitive” stuff of Factor until now so I am excited to see what’s ahead.
