So this is the second time I have tried to "get into" seaside and my initial impression is "man thats a lot of classes" it just feels like total overload but I know that is because I am browsing everything available within squeak as well as smalltalk - still I am just recording my impression so I can come back later and reflect upon it.
I really like the idea of storing class definitions within a db including hierarchy, methods, properties etc. and then fwriting them as actual php class files when necessary. I see this as a sort of compromise/middle ground between the apache and smalltalk image approach. I think that is definitely the direction I will be going with this eventual framework. I want to provide the minimal class hierarchy necessary to create powerful web applications with out including all of the stuff necessary for operating upon the kitchen sink.
The ability to quickly fly through classes/methods and make and commit changes is awesome. It would be pretty easy to include version control this way too!
The other idea based on this structure would be actually storing session instances of given classes.... that's something I am chewing on though in the back of my mind - but for editing/developing I think this idea has wings. Already got a basic interface together using extjs. It will be sweet when things are to the point that I can re-write it in the new language/framework but sometimes a bootstrap is necessary.
Another thing I am for sure wanting to start messing with is the idea of render/adapter-context-free views in that I can define how an interface works with out worrying about the actual display code wether that is html/css or pure extjs etc it should still function with out extra work on my part once the initial adapter is written. So the first step is coming up with what the "interface" for such an adapter would be. An interesting thing to consider is how would one action/view be rendered differently based upon extjs or plain html.
Tuesday, December 9, 2008
trying to put my finger on it
So I am constantly trying to entirely re-evaluate the entire way that I/we currently develop web "applications". There are a few things which profoundly bother me.
Lack of object persistence (I go to a page which is deep with in a business app which requires several "models" to be loaded into memory in order to generate a given interface. Now I want to populate something via ajax so I pass in the relative IDs (or if I am lucky the IDs are in a session, regardless) the page then has to again load those SAME models into memory (temporarily) to fetch some sort of related json tidbit).
Too much coupling to one particular "display stack" i.e. html, css, xhtml, javascript (extjs) - surely my "view" should have the intended layout recorded in a meaningful and timeless manner including callbacks/events and then have it be implemented by what ever adapter/rendering method I choose i.e. html or extjs or svg or what ever comes down the pipeline! this way there is a simple "plugging in" of a new adapter which meets the protocol for rendering and away I go.
My new framework/language/paradigm is going to tackle these problems absolutely.
Lack of object persistence (I go to a page which is deep with in a business app which requires several "models" to be loaded into memory in order to generate a given interface. Now I want to populate something via ajax so I pass in the relative IDs (or if I am lucky the IDs are in a session, regardless) the page then has to again load those SAME models into memory (temporarily) to fetch some sort of related json tidbit).
Too much coupling to one particular "display stack" i.e. html, css, xhtml, javascript (extjs) - surely my "view" should have the intended layout recorded in a meaningful and timeless manner including callbacks/events and then have it be implemented by what ever adapter/rendering method I choose i.e. html or extjs or svg or what ever comes down the pipeline! this way there is a simple "plugging in" of a new adapter which meets the protocol for rendering and away I go.
My new framework/language/paradigm is going to tackle these problems absolutely.
Monday, December 8, 2008
lisp+smalltalk+php ?
So I am closing on a a complete set of rules for my syntax:
The real beauty to this is largely that we can overload operators and not have to use s-expressions to do so i.e. if I decided I wanted / to diff arrays I could easily add a method to the ArrayObject called / which accepts an array as an argument and then calls array_diff between self and the passed array:
#use . to denote end of statement
#list
:(1 2 3 4).
#boolean
($this == $that).
#block
{$x $y | $x*$y}.
#message
[$object method_call: $arg with:[object method:$sub]].
#use ; to denote "with"
[$object methoda;
methodb;
methodc].
#to emulate int objects anytime a square bracket encounters an int
#it will "cast" as intobject thus:
[1 to: 20 do: {$n | echo $n}].
#transmogrifies to
$intObject(1)->to(20)->apply('lambda_block_n');
#it may be the case that the int methods could be factored into more
#procedural form even such as for loops etc. It all depends on performance.
#but pre-optimization is definitely NOT what I am going for here
The real beauty to this is largely that we can overload operators and not have to use s-expressions to do so i.e. if I decided I wanted / to diff arrays I could easily add a method to the ArrayObject called / which accepts an array as an argument and then calls array_diff between self and the passed array:
[:(1 2 3 4 5) / :(2 4 7)]. #yields (1 3 5 7)
#transmogrified to
arrayObj(1,2,3,4,5)->__SYMB_DIV(arrayObj(1,2,3,4,5));
#hmm may get ugly with nested hash
$hash = :(a:(b:(c:true))).
#it feels unbalanced but
$hash = :(a::(b::(c:true))). #is far worse
#or I could stop being an idiot and use #
[#(1 2 3 4) each {$n | echo $n}].
#my only hesitation is as illustrated here, # is used for comments in c-alikes.
more on syntax
The more I think about it the more it becomes apparent that logically using square brackets for codeblocks/lambdas does NOT make sense for what I am trying to accomplish with let. Using { } for anon blocks and ( ) for lists as well as "grouping" and boolean statements makes much more sense thus saving square brackets for sub-statements and removing [ ] from arrays entirely as they can use dot notation or accessor methods. Consider:
Notice in the last one that this makes square brackets the equivelant of "apply" and keeps open brackets for grouping and or boolean operation which is what people coming from php would expect. The { } also feels more natural for anon code blocks for php-centric people as well.
Another approach would be using square brackets for "messages" sort of like obj c but more like sugar for dropping dots in objects i.e.
$list = (1 2 3);
$list.each {$x | echo $x};
$number = let ($x = 10){
(add:{$y | $x += $y}
sub:{$y | $x -= $y});
#note if we wanted the method to be named add: we would do 'add:':{$y | $x += $y}
}
$number.add 10; #20
$number.sub 5; #15
#And from last time:
$decide = {$char | $char == a ? sum : mul};
$num = 10;
$letter = a;
$result = [$decide char:$letter] 6 6 ($num + 50);
Notice in the last one that this makes square brackets the equivelant of "apply" and keeps open brackets for grouping and or boolean operation which is what people coming from php would expect. The { } also feels more natural for anon code blocks for php-centric people as well.
Another approach would be using square brackets for "messages" sort of like obj c but more like sugar for dropping dots in objects i.e.
$range = (1..5);
[$list reverse each {echo _}]
#becomes
function block_name($arg0){echo $arg0;}
$list->reverse->each('block_name');
Sunday, December 7, 2008
philosophy of duality of syntax
Now for a more text-ful approach to describing the problem and my approach towards a solution. It's interesting that as I have been slowly changing php to suit my needs I have been grappling with the issue of consistency much like the developers of py3k have. It seems that in an attempt to "make things consistent" they have tried to make everything work like a function i.e. no more print 'string', now it is print('string') - this feels, to me, like they took the wrong fork in the road. Instead of making print work like a function why not make all functions work like keywords/in built functions?
I guess I am in my ivory tower but really if I am going to create a language/dialect which I ENJOY coding in day in/day out I am not worried about backward compatibility and or what people are used to - I am worried about what makes things consistent and beautiful. The obvious choice for the most consistent approach would be straight s-expressions but there is something to be said for the readability of declaration and assignment. My approach is basically s expressions with out the initial brackets i.e.
Now I can fully see how the s-expression is more perfectly recursively consistent but I personally find the prior approach more readable and for "in the main" programming it would be the most maintainable.
Something I have been toying with is the idea of how to transmogrify dynamic function calls in s-expressions:
I guess I am in my ivory tower but really if I am going to create a language/dialect which I ENJOY coding in day in/day out I am not worried about backward compatibility and or what people are used to - I am worried about what makes things consistent and beautiful. The obvious choice for the most consistent approach would be straight s-expressions but there is something to be said for the readability of declaration and assignment. My approach is basically s expressions with out the initial brackets i.e.
#LET
$x = func arg:val arg1:val2 arg2:(func1 arga:vara);
#s-expr
(setf x (func arg:val arg1:var arg2:(func1 arga:vara)));
Now I can fully see how the s-expression is more perfectly recursively consistent but I personally find the prior approach more readable and for "in the main" programming it would be the most maintainable.
Something I have been toying with is the idea of how to transmogrify dynamic function calls in s-expressions:
$decide = [$char | $char == a ? sum : mul];
$num = 10;
$letter = a;
$result = ($decide char:$letter) 6 6 ($num + 50);
#should become
$result = sum 6 6 ($num + 50);
#which becomes
$result = sum(6,6,($num + 50));
duality of syntax
So I have hit a bit of a conondrum with my current approach to introducing a new syntax for lambdas in LET/php.
The problem comes from the current use of square brackets to access array elements mixed with my desire for them to be lambda expressions. Consider the following:
The problem comes from the current use of square brackets to access array elements mixed with my desire for them to be lambda expressions. Consider the following:
$array = (a b c d);
$array [0]; #a
#the function expecting the yield block is passed a block which returns 0
$expecting_yield [0];
#one solution as we have dropped ( and ) for calling functions would be using
#that for array indexes, this would sort of fit with the fact that it is used
#for defining arrays.
$array = (a b c d);
$array(0); #a
$array (a:(b:(c:cat)));
$array(a)(b)(c); #cat
#what about methods stored in arrays?
$number = let($num = 5){
(mul:[$x | $x * $num]
div:[$num/_])
}
#note that _ is for anon vars and _1 _2 is if there are many
$number (mul) 10; #50
#that feels odd.
#using magic __get and keyword param
$number.mul x:10;
#that works well for keys which are strings but what of numeric index?
$array = (1 2 3 4);
$array.0 #1
#perhaps we could be clever enough to turn numeric dots into
$array[0]
#if all arrays are objects then why would you not use an accessor method?
$array = (1 2 cat 4);
#or using an accessor method - thats only one extra char (the .)
$array.at 2; #cat
#maybe removing the [ ] notation will encourage functional programming
#instead of iterating over for loops anyway?
#but what about look ups in a hash table?
$actions = (cat:walks rat:crawls bat:flies);
(cat rat bat).each [$creature |
echo "the $creature {$actions.$creature}";
];
#normal php
$actions = Array('cat'=>'walks', 'rat'=>'crawls', 'bat'=>'flies');
foreach(Array('cat','rat','bat') as $creature){
echo "the $creature {$actions[$creature]}";
}
Friday, December 5, 2008
more on let blocks
So as an aside the two are equivalent:
The let block is obviously more readable as you understand you are creating a binding for $x and then using that binding in the let block (in this case to return a function which closes over $x).
So to leverage the power of multiple-transmogrifications the system first translates let blocks to be square lambdas and then the square lambda transmogrification can just handle everything else (including closures). I think it's dope.
$func = let($x = 10){
[$y | $x = $x*$y];
}
$func = [$x | [$y | $x = $x*$y]] x:10;
The let block is obviously more readable as you understand you are creating a binding for $x and then using that binding in the let block (in this case to return a function which closes over $x).
So to leverage the power of multiple-transmogrifications the system first translates let blocks to be square lambdas and then the square lambda transmogrification can just handle everything else (including closures). I think it's dope.
Subscribe to:
Posts (Atom)