A second installment of my attempt to code erlang-style concurrency abstraction in haskell. The effort in part I, was a bit short of the mark. Here I try to address some of the shortcomings, while leaving others open.
The main problem was that the receiver could escape outside of the process, which can cause various hard to debug mayhem. What will happen if two different threads receive data from the same channel? Yes, it might be intentional, but you could always duplicate a channel for that. What if it is a bug? What if it is a piece of malicious code? Better safe than sorry.
I'm on a learning haskell journey. But reading someone else's code and thoughts while educational is not that enlightening. Anyway, to cut the long story short:
So this is how ended with Why not try my hand at erlang style concurrency. The best thing about it is that it aligns nicely with an individualistic view of the world. I can write sequential code to do something, which from time to time communicates with the rest of them, while the rest of the time doesn't really care.
Erlang implements lightweight processes with asynchronous messaging. The cool twist it puts on it is having reception guards - if a message is not matched by the guard conditions it stays in the mailbox (channel), and the rest of the messages are scanned. The first matching message is removed from the mailbox, the remaining messages are left in the mailbox in arrival order.
Up until now I was avoiding putting my thoughts on 'paper', but here we are. My instincts simply say Restricting knowledge distribution and use is wrong. Some might say this makes me a communist devil, anarchist or whatever other epithet is currently cool in their circles. Let's avoid that for the time being. These scribbles are probably not 100% correct. But the ideas are what matters anyway. And will you find a difference from a bird's eye view?
Obviously this is a strong social issue, as in it reflects a growing concern of the society as a whole. The society as the human beings represented by a state, like UK, USA, France, Bulgaria, or groups of states like EU, UN, ... Some long time ago patents were introduced by the British Crown in order to give a temporary monopoly to inventors, so that they can protect and exploit their knowhow, while making the knowledge (their knowhow) public. This was a significant social issue. This way knowledge was immediately becoming exploitable by the society. People could benefit from the abstract knowledge or the principles behind the patentable invention. These principles were not patentable at the time, only some of their defined applications - the invention, machines, products etc... The monopoly lasted for a relatively short period of time. Longer than it would take at the time to reverse engineer an invetion and set up production of a competitive product, but not by too much. This is important, since timescales, im my opinion, are important when trying to rationalise the costs of patents to a society.
inspired by Verity , my urge to display my writing talent and random buzz on the internet
This conversation was (allegedly) overheard in a nursery, which won't be disclosed to avoid litigation
Write a standard php loop on the nursery blackboard
Come on, can't be bothered. Are you joking?
foreach( $array as $key => $value ) echo "$key $value";
Wrong! Don't you ever learn proper language usage
What have I done NOW?
Happy birthday Jess, hope you delve deeper in your obsession with men with long hair, or your other (inked) ones for that matter.
And see you down the pub.
I know that I often express myself in an overcomplicated way. I hope I don't do that in code. I'm really amased how people overcomplicate stuff in their minds. This particular rant is triggered by me wandering around the net flicking design patterns in php web pages.
Guess what? They are complex beasties. With multiple hierarchies of classes doing loads of complicated stuff over a lot of lines of code.
Take a look for example at Observer Pattern. Actually not a very bad code. Still on the big side. Still maintaining the dual observer/observed 'magic' separation. Compare it with this hooks implementation, the code at the bottom of the page. The latter is designed for a more complex scenario, i.e to mimic aspects in php, but still manages to be simpler.
But the best example, I suppose, is how do you code a strategy pattern in php? A typical code would be something like Strategy Pattern. Not a bad code. Well described, documented, etc... But wait! A startegy is:
The Strategy pattern defines an object that represents an algorithm for a particular task.
But algorithm == function (or method), isn't it? So the variable function problems is I think this should do it. Yep, for complex strategies you might need to compose stuff, but still there are surely better ways, rather than having these long hard java/c++/... inherited ideas.$func = "a_function";
...
$func()
call_user_func('a_callback_function');
call_user_func(array('AClass', 'aCallback'));
call_user_func(array($obj, 'aCallback'));
$callback = 'a_callback_function';
$callback();
$callback = array($obj, 'aCallback');
$callback();
What can we use this for? The most obvious and straight forward this is a lightweight state pattern implementation -
$a_thing()
Will behave differently depending on the value of the $a_thing variable, it's state. Another way to look at php callbacks is as proxies for 'real' functions, class or object methods.
Oh, let's not forget is_callable, it's a very useful little number.
The facility of PHP objects to encapsulate a state and us being able to access this state later can be used to turn them into functions. Let's consider:
class aClass{
var $state;
function get() { return $state; }
function next() { $state=random; }
function callbacks() { return array( array($this,'get'), array($this, 'next'));}
}
$obj = new aClass();
list( $random, $next_random ) = $obj->callbacks();
echo $random();
echo $next_random();
This talk dissects the code generated by Visual Studio; analyzes the appalling programming practices it perpetuates; rhapsodizes about the joys, frustrations, and satisfactions of unassisted coding;
Does visual studio rot the mind
Nice. I like that article, not so much because it slags a Redmond born product, but that it goes to the core - bring back fun, in all it's forms, into programming. Just say no to ugly code.
I really want elegant code back. Unfortunately there is too much of the quick fix hack smartly generated crap bloat.
My obsession with things schemish and lispish and having to use php on a daily basis leads to the usual comparison and how would I do this in ... style questions. So here comes another go at how would I program lisp style in php. How much is possible? What is possible? Mind you not everything is really useful or the best way to do it. It is just an intellectual excersise, a study on using some of the php'f features to program in not a typical php (imperative) style.
Well for the benefit of non-lispers I will use head and tail instead of car and cdr respectively.
What a man!
I wish I was blonde and female. Never mind.
Cheers buddy, a year is not that much.