- I encountered a problem with my test data.
- I resolved some problems with lists and test data.
- I resolved some problems with dictionaries.
The next problem that I resolved had embarrassingly little to do with the erlang libraries. With "imperative" languages like Java I am used to doing something like this:
int foo = 1;
foo++; // foo now has the value 2
Whereas with a functional language like erlang, one instead uses something like this:
Foo = 1;
Foo2 = 1 + Foo;
This is because in languages like erlang, you cannot change a variable once it has been set. Personally, I don't think one should use the term "variable" to describe such an object in erlang, but I digress.
The problem I was running into was that I was not updating the variable that I changed. Thus I would use something like this:
put_data(State, ConnectionID, Data) ->
NewState = update_table(State, ConnectionID, Data),
{ Result, NewerState } = remove_waiter(ConnectionID, NewState),
case Result of
undefined -> NewerState;
Waiter -> notify_waiter(Waiter, ConnectionID, State)
end.
Whereas what I really wanted was something like this:
put_data(State, ConnectionID, Data) ->
NewState = update_table(State, ConnectionID, Data),
{ Result, NewerState } = remove_waiter(ConnectionID, NewState),
case Result of
undefined -> NewerState;
Waiter -> notify_waiter(Waiter, ConnectionID, NewerState)
end.
Nothing really Earth shattering here, just ye basic functional vs. imperative programming styles. This will not stop me from complaining, but I'm just saying...
Next time: more testing goodness.
No comments:
Post a Comment