YAWS

You are currently browsing the archive for the YAWS category.

I decided to switch my multi-virtual machine test/dev setup over to a minimal Debian install, not least because I couldn’t keep my mind off the fact that I was carting around a full desktop installation along with various ‘pretty’ desktop backgrounds, system administration for GUI-monkeys applications, and god knows what else. One batch of this stuff is bad enough, but repeated N times it’s too much for me to handle.

Read the rest of this entry »

The Erlyweb DJ app

I stayed up far too late last night playing with Erlang and friends – much longer than planned due to a few hitches. I did manage to complete more or less what I’d planned in the end though, so here is the documentation.

Read the rest of this entry »

Building on the steps in the previous parts of this series, I’ve added ErlyWeb into the equation. ErlyWeb is a web application framework built on Erlang/YAWS which I’ve been reading a bit about recently. As well as the main web site linked above, Yariv Sadan‘s blog is a good source of information.

Read the rest of this entry »

Part 4 of the series, documenting the setup of an Erlang test platform. In this episode, it’s YAWS (discussed previously here) that we’re adding.

Read the rest of this entry »

YAW(N)S

Last post on this subject for now, hopefully, since even I’m getting bored of it. Just for the sake of completeness, I did the ISO date formatting ‘properly’, as follows:

w3cdtf(GregSecs) ->
	Date=calendar:gregorian_seconds_to_datetime(GregSecs),
	[UDate|_]=calendar:local_time_to_universal_time_dst(Date),
	USecs=calendar:datetime_to_gregorian_seconds(UDate),
	{{Y, M, D},{HH, MM, SS}} = Date,
	io_lib:format("~4..0b-~2..0b-~2..0bT~2..0b:~2..0b:~2..0b~s",
		[Y,M,D,HH,MM,SS,tzid(GregSecs-USecs)]).
 
tzid(Secs) when Secs==0 ->
	"Z";
tzid(Secs) ->
	{HH,MM,_}=calendar:seconds_to_time(abs(Secs)),
	io_lib:format("~c~2..0b:~2..0b",
		[case Secs >= 0 of false -> $-; true -> $+ end,HH,MM]).

As well as being shorter and clearer still, it doesn’t use the calendar:time_difference like the original did. That’s good because not only is that function very silly, it turns out it is marked as obsolete in the documentation. I suspect those two points are not unrelated.

Anyway, I’ll probably give the above some more rigourous testing and submit a patch. It may seem rather trivial, but actually it was a good exercise in getting to know Erlang a bit better. Half an hour of practical problem is usually worth ten of reading TFM.

YAWS continued

There was a suggestion in the comments that the code excerpt I showcased in my previous post was not shit at all, but rather just the way you do things in a functional programming language. By way of illustrating why it actually is shit, I present the following code that does exactly the same thing, using the same methodology:

less_shit(GregSecs) ->
	Date=calendar:gregorian_seconds_to_datetime(GregSecs),
	{{Y, Mo, D},{H, Mi, S}} = Date,
	[UDate|_] = calendar:local_time_to_universal_time_dst(Date),
	{DiffD,{DiffH,DiffMi,_}}=calendar:time_difference(UDate,Date),
	i2l(Y) ++ "-" ++ add_zero(Mo) ++ "-" ++ add_zero(D) ++ "T" ++
        add_zero(H) ++ ":" ++ add_zero(Mi) ++ ":"  ++
        add_zero(S) ++ tzid(DiffD,DiffH,DiffMi).
 
tzid(DiffD,DiffH,DiffMi) when DiffH < 12,  DiffH /= 0 ->
	"+" ++ add_zero(DiffH) ++ ":" ++ add_zero(DiffMi);
tzid(DiffD,DiffH,DiffMi) when DiffH > 12,  DiffD == 0 ->
	"+" ++ add_zero(DiffH) ++ ":" ++ add_zero(DiffMi);
tzid(DiffD,DiffH,DiffMi) when DiffH > 12,  DiffD /= 0, DiffMi /= 0 ->
	"-" ++ add_zero(23-DiffH) ++ ":" ++ add_zero(60-DiffMi);
tzid(DiffD,DiffH,DiffMi) when DiffH > 12,  DiffD /= 0, DiffMi == 0 ->
	"-" ++ add_zero(24-DiffH) ++ ":" ++ add_zero(60-DiffMi);
tzid(DiffD,DiffH,DiffMi) when DiffH == 0 -> "Z".

The point to note is that no complex expression is repeated multiple times, and nor is the actual logic of generating the timezone identifier buried within one. It’s much clearer, and much shorter.

Another point to note is that it is still shit, and I make no apologies for that, as firstly I wanted to keep the methodology the same, and secondly I am still getting to grips with Erlang.

YAWS

I said I would have another look at YAWS, given the apparently amazing performance. I decided to dive straight into the source, since I had more than a hunch that anything substantial written in Erlang would be an unmaintainable mass of crap. I certainly wasn’t disappointed in this case. The following excerpt is one of several chunks of code I came across that do exactly* the same thing:

Read the rest of this entry »

I decided to have a brief play around with Erlang a couple of weeks ago. If you don’t know what it is already, you are unlikely to be interested, so switch off now. On the other hand if you do know what it is, I’m sure you know more than me about it, so switch off now. That leaves me writing for my future self, who is probably here either trying to refresh his goldfish-like memory or wanting a chuckle at what his former self got wrong.

Read the rest of this entry »