terminal-auspicious

Topics

programming

php drupal scheme scheming macros design patterns da la

design

design css

random thoughts

scribbles

alter ego

other me 'em that link us my space me linked in

Collections

Programmable web
PHP design patterns

Home

scribbles

Learning to speak - erlang style concurrency in haskell ( part II )

Submitted by vlado on Fri, 2007-11-23 00:19.code | erlang | haskell | scribbles

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.

read more | vlado's blog | add new comment | 2 attachments

Learning to speak - erlang style concurrency in haskell

Submitted by vlado on Thu, 2007-11-15 17:41.code | erlang | haskell | scribbles

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:

  • I (still) want to see what this haskell thing is all about
  • I need a moderately complex problem to get a feeling of the haskell type system works, face the dreaded IO, while not wasting too much time
  • I need a decent actor style abstraction for some social/population based methods experiments I'm into

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.

read more | vlado's blog | 2 comments | 2 attachments

software patents, or my personal insights

Submitted by vlado on Fri, 2006-09-29 13:10.copyright | digital rights | Intellectual Property | IP | politics | scribbles | society | wrongs

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.

read more | vlado's blog | 2 comments

out of the (php) loop

Submitted by vlado on Wed, 2006-08-09 16:32.php | programming | scribbles

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?

read more | vlado's blog | add new comment

Hey Jess, hope you see this in time ;)

Submitted by vlado on Wed, 2006-08-09 11:24.friends | scribbles

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.

vlado's blog | 1 comment

Overcomplicated design pattern implementations

Submitted by vlado on Mon, 2006-07-24 17:09.code | php | rants | scribbles

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 $func = "a_function"; ... $func()

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.

read more | vlado's blog | add new comment

Scoped php functions or more ways to abuse php

Submitted by vlado on Mon, 2006-07-24 10:09.code | coding | design patterns | php | programming | scribbles | work in progress
Here we go again. In this writeup I'll revisit the ideas of closures, state and closures, partial evaluation and generics.

Basics of 'functions as first class language objects'

Yep. PHP can assign functions to variables. In this sense functions are first class objects. Object and class methods are similar, you can, kind of, assign them to variables and later execute them. What does this change? Well, it improves our ability to abstract common patterns and idioms. There are examples of this in the above writeups as well as in the aspects one and quite a few of the rest of php ones on this site. The basic concept is php callback for example: 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.

Objects and functions

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();

read more | vlado's blog | add new comment

Does Visual Studio Rot the Mind?

Submitted by vlado on Mon, 2006-07-03 15:14.programming | scribbles

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.

vlado's blog | add new comment

LISP-like programming in php

Submitted by vlado on Thu, 2006-06-22 13:12.lisp | php | scheme | scribbles

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.

the compulsory conses, car, cdr in php

Well for the benefit of non-lispers I will use head and tail instead of car and cdr respectively.

read more | vlado's blog | add new comment

Army man

Submitted by vlado on Tue, 2006-05-09 11:18.charilaos pasantonopoulos | friends | scribbles
Charlie is going to the army. Tomorrow. Sad isn't it. He is going to waste a year of his time serving his duty to his country. Skipping the fact that this is simply %$&#@, let's admire the view Charilaos Pasantonopoulos, aka Charlie What a man! I wish I was blonde and female. Never mind. Cheers buddy, a year is not that much.
vlado's blog | add new comment
123next ›last »
Syndicate content
Home

dikini.net

spreading confusion by accident since 1970