7,244 karma · joined Sep 25, 2010 (16y ago) · 2,593 submissions
comment 13y ago · link · parent
To clarify, this is related to the parallel execution of a single query. PostgreSQL has been making huge improvements scaling to many cores when there are many concurrent queries.
Even for single queries, postgres has been chipping away at the edges by moving more tasks to background processes.
comment 13y ago · link · parent
When you say my example is incorrect, do you mean that it's incorrect in clojure, or only in scheme? I tried my examples in clojure and they appear to work and appear to demonstrate a lack of referential transparency. I assume that clojure is a valid lisp to make a point about metaprogramming and macros.
Also, it looks like it's fairly easy in scheme to show the same thing, which it looks like you started to do (I'm not sure whether you agree with me about that or not):
(define-syntax swapargs
(syntax-rules ()
((_ ls) (list (list-ref ls 0) (list-ref ls 2)
(list-ref ls 1)))))
(define a 7)
(define b 5)
(eval (swapargs '(modulo a b))) => 5
(define a 10)
(define b 8)
(eval (swapargs '(modulo a b))) => 8
The two calls to "eval" are identical, yet return different results. That breaks referential transparency."showing the particular merit of Scheme"
From what I know, I like lisps of various flavors. I just said that they didn't really speak to the kinds of problems that I deal with. Maybe if I wrote more lisp I would see why it does so, but currently I do not.
comment 13y ago · link · parent
No, my problem identifying with Manning was that he exposed private communications involving the State Department, which could have consequences for our foreign relations and national security. Swartz was downloading scientific journals, which is an entirely different ballgame.
Very few people believe that State Department communications should be public. So, even if you convince everyone that some injustice was done to Manning because of specific situations that called for whistle-blowing, it does not reveal any general problem in the federal justice system.
With Swartz, I think just telling his story will cause many people to realize how broken the federal justice system is.
comment 13y ago · link · parent
* Why is this a Federal crime at all? Because some computer in another state was involved? If so,then soon all crimes will be federal.
* It appears they used mostly catch-all laws. The vague wording is subject to confirmation bias where almost any action looks like a violation. This is a particular problem with laws related to computer use; but also includes laws like "obstruction of justice" and "lying to a federal agent".
* In order to have a "reasonable" sentence on the table at all, he has to give up his right to a trial.
* As far as I can tell, no damage was actually done to anyone yet.
* Since when is violating a TOS a criminal issue? Did we outsource the writing of laws to company legal teams?
comment 13y ago · link · parent
Really, what I meant was the metaprogramming associated with homoiconicity can't be done in a useful and referentially transparent way. That's because "eval"-like things are not referentially transparent.
However, there are other uses for homoiconicity aside from executing the code in an eval-like way. For instance, a text editor might use that property to inspect and transform the code being edited more easily. Also, I'm sure there are plenty of times it just makes things easier.
I think metaprogramming is also at odds with static analysis (e.g. a good type system), simply because the code itself is not static enough to analyze.
comment 13y ago · link · parent
Anyway, I tried learning enough clojure to prove that routine metaprogramming would often be not referentially transparent.
First, note from the wikipedia page that "referentially transparent" essentially means that the same function with the same arguments will always produce the same result, and that you can call it more (throwing away the result) or fewer (replacing calls with the result) times without affecting the meaning of the program.
So, mutating variables (assignment) violates it, as does reading mutable variables other than the arguments. So, using "def" on a variable that already has a value is not referentially transparent.
But let me show you something closer to what I had in mind when I said that referential tranparency and metaprogramming are essentially inconsistent.
Take the simple macro:
(defmacro swapargs [x]
(list (nth x 0) (nth x 2) (nth x 1)))
First, I'll show that the argument that it takes must be the code itself, rather than the result of evaluating the code. The "or" macro before made it hard to tell whether it was taking the code as arguments or the result of evaluating the code as arguments. But with the macro above, it's easy to see: (swapargs (mod 7 5)) => 5
(swapargs (mod 10 8)) => 8
If we are trying to show that swapargs is referentially transparent, we assume that it will return the same result given the same arguments. Because (mod 7 5) = (mod 10 8), then we know it must not be taking the result as an argument (because the result of the mod is 2 in both cases, but the result of swapargs is different). So it's taking the code itself.Next, we show that give the same code-as-an-argument, it may return different results in different contexts. That's easy to show:
(defn foo [a b] (swapargs (mod a b)))
(foo 7 5)
(foo 10 8)
Now, we can't replace the call to swapargs with its result, because it changes depending on the values of "a" and "b" at the time, even though the argument is always the same code "(mod a b)".So, this kind of advanced metaprogramming doesn't seem compatible with referential transparency. Perhaps some subsets are, but I don't even think the C macro system could be supported in a referentially-transparent way.
I also think that kind of metaprogramming tends to defeat many kinds of static analysis, such as advanced type systems. I'm less sure of that one, but for practical purposes now it seems to be true.
So, I think lisp and haskell are close to local maximums for their particular philosophies, but neither one is any kind of epitome of programming or "more powerful" than the other.
Personally, I think lisp-style metaprogramming is very cool, and I am happy I spent a few minutes trying out clojure. However, I don't think it is solving a problem that is very important to me at a practical level. I am trying to learn haskell because it is trying to solve the kinds of problems that I actually have -- mainly software engineering problems (greater confidence in code, more readability and maintainability). Not sure whether it will help solve those problems for me, but they are trying very hard to do so, and make some pretty compelling arguments.
comment 13y ago · link · parent
My clojure interpreter gives "10" not "20".
The function "or" is referentially transparent, because if you call it with the same argument values you are going to get the same result every time. (or 10 20) is the same as 10.
However, the following function is not referentially transparent:
(defn incx [] (do (def x (+ x 1)) x))
Because subsequent calls return different results: (def x 2)
(incx)
(incx)
Things like side effects and many kinds of metaprogramming break referential transparency.comment 13y ago · link · parent
Although that may compromise the ability of the compiler to detect mistakes even when the developer writes all referentially-transparent functions. Not sure about that, but I suspect that it does in practice (currently) even if not theoretically inherent.
comment 13y ago · link · parent
That was incorrect, I meant: "the kinds of metaprogramming associated with homoiconicity are mutually exclusive with referential transparency".
A macro could not, for instance, take a variable name as an argument and return a result that's based on the value of that variable and maintain referential transparency. So that would be a pretty weak macro system.
I suppose there may be other uses for homoiconicity, but I don't know enough about lisp to comment on that.
comment 13y ago · link · parent
But if you already have some tests in place, the most efficient way to reduce bugs is often something other than more testing, e.g. code review, design review/improvements, or static analysis (often provided by the language/compiler).
All of those other methods can and will reduce bugs. So your statement that testing is the only way is obviously false in both a practical and theoretical sense.
comment 13y ago · link · parent
Language "power" is ill-defined, and basically means "good".
If you think that homoiconicity is good, then you probably like lisp. If you think that referential transparency is good, then you probably like haskell. Those are mutually exclusive, so one language can't really have both. But either one could be considered "powerful" and either one could be said to help prevent bugs.
comment 13y ago · link · parent
Even if you have perfect time-warping capabilities, there are still big challenges to solving bugs with that kind of analysis. The time the bug is noticed may be long after the root cause, and working backward could be a very slow process.
That's why SQL has declarative constraints, to try to make the error noticed at a time closer to the root cause.
Would I like full time-warping capabilities sometimes? Of course. But it's just one more option, and a very expensive one at that. To be any use at all, we'd need to be able to warp backwards through the entire OS and its scheduling decisions (not just a single process), because many difficult bugs involve race conditions.
Really, we need better temporal capabilities, and more declarative constraints (that are immune from race conditions, like a UNIQUE constraint), better ways of avoiding race conditions, etc.; and they all need to work together.
That's why I have worked on temporal capabilities[1] as well as declarative constraints [2] (immune from races) in Postgres. Also, you might be interested in truly serializable transactions in postgres, which eliminate race conditions between transactions without blocking[3].
I feel like the programming language community should work more with the database community. From the article, they mention how restarts can help recover from errors encountered after part of the state has already been changed. But that kind of recovery is taken for granted with the atomic nature of transactions in a database. Database theory is largely about detecting, containing, mitigating, recovering from, and preventing errors[4].
[1] http://www.postgresql.org/docs/9.2/static/rangetypes.html [2] http://www.postgresql.org/docs/current/static/sql-createtabl... [3] http://drkp.net/drkp/papers/ssi-vldb12.pdf [4] http://thoughts.davisjeff.com/2009/12/23/good-error-recovery...
comment 13y ago · link · parent
I wasn't making an argument; merely asking for numbers and explaining why the existing numbers may be deceptive.
"a lack of evidence for second and third generation immigrants being significantly better off."
Do you have some numbers to back that up? I'd like to see them broken down by country of origin, if possible.
comment 13y ago · link · parent
For instance, let's say that people in the next generation decide to go to college for 10 more years, leaving at 32 rather than 22. Then, when they get out, they make 50% more income than the previous generation. Overall, they might be better off throughout their life; but the statistics will make it look like there is a huge lower class (who are in fact just young and haven't reaped the benefits of their education yet).
The more our earning is concentrated to a small part of our lives, the more it will look like class divisions. And depending on how the accounting is done, the upper classes may consist largely of people with temporarily high incomes (from inheritance, selling a house, etc.).
[None of the above is meant to imply that there is not a problem. Just that statistics can be deceptive, and can hide the real solutions from us.]
EDIT: Specifically, I think it would be interesting to divide people into classes like: "X% of people will see an income over $80K sometime during their lives". That seems like a better indicator of opportunity to me.
comment 13y ago · link · parent
All of those things apparently contribute to traffic more than people who travel in random directions at random times.
Also, it means that it is (potentially) more of a fixable problem. If you can target those specific sources and destinations of problem drivers, you can try to offer them alternatives. Even if they are replaced by other drivers, many of those other drivers may behave more randomly, and the roads will have better utilization.
comment 13y ago · link · parent
It's basically as educational as anyone at a cocktail party talking about the good deal they got on a car. Except in that case, you'd at least get the numbers.
comment 13y ago · link · parent
I think that is generally a mistake for non-trivial applications. MySQL and SQLite are so far from the standard that it's just not worth trying to find a subset of SQL that works the same on those systems as the others.
The similarities between the SQL implementations do make porting easier, however. But I consider it a port rather than using a common subset.
comment 13y ago · link · parent
I can understand if you're worried about using Oracle or something. But if it's a free software database system, the code is open, and I don't really see that as "lock in". For comparison, if you write an application in ruby, you don't say that you are "locked in" to ruby.
"I think an API is a lot cleaner"
That can work very well, but it does have some weaknesses. For instance, you may see a check in the API code for out-of-bounds values, and assume your code doesn't need to account for it. But then you hit some out-of-bounds data at runtime, because the data was inserted before the check was added. That's why databases offer many declarative constraints, so that if you see it, you know it's true, and don't have to worry about when the constraint was created.
That being said, I think a lot of applications would be better developed using something like a web service to cleanly separate the human interface from the action being taken. I can't think of many ways to do that without a lot of boilerplate code though.
comment 13y ago · link · parent
However, it isn't necessary to solve the problem. It would be relatively easy to use a row lock in this case to solve the problem, as well, but I like to avoid those unless there's a reason.
If you want to have a mix of SERIALIZABLE and other transactions, or you are worried about making a mistake (or some malicious user), then you need to use the row lock. Eventually there should be a way to force users into serializable transactions.
EDIT: actually, in the trigger, you could explicitly check if the transaction isolation mode is serializable. That would be the best approach:
if current_setting('transaction_isolation') <> 'serializable' then
raise exception 'serializable mode required';
end if;comment 13y ago · link · parent
The reason it seems simple when using a few classes is because there is an implicit assumption that concurrency is a non-issue and there's only one application involved. But those aren't good assumptions, so the approach using classes will start to look more complex (and involve locks, etc.).
In Postgres, the trick is to use SERIALIZABLE transactions everywhere (should be the default, eventually), which avoids the need for explicit locking. Then, add a trigger that is fired before changes to either table, and it would simply check that the condition holds for the quote that was modified.
Here's some code, since you asked:
create table quote(
quote_id int8 primary key,
customer_id int8,
valid daterange
);
create table quote_line(
quote_id int8 references quote(quote_id),
amount numeric(10,2)
);
create or replace function check_quote() returns trigger language plpgsql as $$
declare
line_count int;
line_sum numeric;
begin
select into line_count, line_sum
count(*), sum(amount) from quote_line where quote_id=NEW.quote_id;
if (line_count < 1 OR line_sum < 0 OR line_sum > 1000000)
then raise exception 'invalid quote';
else return NEW;
end if;
end;
$$;
create constraint trigger quote_check_trig after insert or update or delete on quote deferrable initially deferred for each row execute procedure check_quote();
create constraint trigger quote_line_check_trig after insert or update or delete on quote_line deferrable initially deferred for each row execute procedure check_quote();
Note that I did not need to add the CHECK constraint, because it's much better to use the appropriate data type -- DATERANGE -- instead of hacking it together from parts.comment 13y ago · link · parent
Those types of requirements rarely have a big impact on the design. Sure, you might have to write some procedural code in a trigger, but that's just a handful of lines of code. (I don't know why you think the "from_date < to_date" is a difficult requirement though -- as someone else pointed out, that's just a CHECK constraint).
Relational modelling is often a very clean, concise, and readable way to represent many kinds of businesses. You can pile a few extra requirements on top, and a good DBMS will make it easy to do so.
So I don't see a "hard failure" of anything here.