Extend database abstraction layer, to include table creation.
http://drupal.org/node/63049 Now that we have .install files for modules, I believe it is time we extended our database abstraction layer. I recommend we create the following extra functions : 1. db_create_table($tablename, $columns); // columns is an associative array with the 'name' => 'type' 3. db_drop_table($tablename); 3. db_create_index($tablename, $columns); // columns is an array of column names, or just a single column. 4. db_drop_index($tablename, $columns); 5. db_add_column($tablename, $column, $type); // PGSQL already has a similar function, but it isn't in both systems. 6. db_drop_column($tablename, $column); The installer that is coming in, will be converting the database.*sql files into a system.install file, and with these functions, we can collapse ALL THREE SCHEMA FILES, into a single, much simpler file. This will also _drastically_ simplify updates, and it will give us consistent usage of types across the database. Certain things will still need to happen only on postgres (like create function calls for instance), but this DRASTICALLY decreases the amount of work we have to do to support multiple db types. At the moment, there are no create table statements that can be changed in core itself (until we have a system.install) , however, contrib modules can already be ported to use these functions, which would mean that we have (preliminary) postgres support across the board on all contrib modules. These functions should possibly keep track of what tables / columns / indexes have already been created, that would allow us to check (in a cross db way) what tables are available, and maintaining this information could possibly be useful in the future, such as not creating tables which have already been created. Additionally, each of these functions can be used to trigger a process for entering additional database credentials, in the case that the specific database user is not allowed to create tables and the like. This also helps make the patch for the installer a lot simpler, so if you want to help out with the installer, this would be a good thing to get involved with =) -- Adrian Rossouw Drupal developer and Bryght Guy http://drupal.org | http://bryght.com
Adrian Rossouw wrote:
Now that we have .install files for modules, I believe it is time we extended our database abstraction layer.
I recommend we create the following extra functions :
1. db_create_table($tablename, $columns); // columns is an associative array with the 'name' => 'type' 3. db_drop_table($tablename); 3. db_create_index($tablename, $columns); // columns is an array of column names, or just a single column. 4. db_drop_index($tablename, $columns); 5. db_add_column($tablename, $column, $type); // PGSQL already has a similar function, but it isn't in both systems. 6. db_drop_column($tablename, $column);
I'm in favor of adding these functions -- but if and only if we also add a database privilege escalation feature for the site admin to use. Many hosts with *better* security provide multiple database users with tiered privileges specifically so that web applications can access the database without full create/drop rights. Widespread use of the above functions will break Drupal on those hosts. (yes, that means my sites :-) ..chrisxj
On 11 May 2006, at 9:20 PM, Chris Johnson wrote:
I'm in favor of adding these functions -- but if and only if we also add a database privilege escalation feature for the site admin to use. Many hosts with *better* security provide multiple database users with tiered privileges specifically so that web applications can access the database without full create/drop rights. Widespread use of the above functions will break Drupal on those hosts. (yes, that means my sites :-)
I agree. This would also be useful for the install system. Although a case could be made that that is a separate patch. And i did mention the privilege escalation in my post =) -- Adrian Rossouw Drupal developer and Bryght Guy http://drupal.org | http://bryght.com
On Thu, 11 May 2006 20:31:32 +0200, Adrian Rossouw <adrian@bryght.com> wrote:
Now that we have .install files for modules, I believe it is time we extended our database abstraction layer.
I recommend we create the following extra functions :
1. db_create_table($tablename, $columns); // columns is an associative array with the 'name' => 'type'
Ah yes. And between 'character variable' of postgres and 'varchar' of mysql, which one ?
On Thu, 11 May 2006 20:31:32 +0200, Adrian Rossouw <adrian@bryght.com> wrote:
Now that we have .install files for modules, I believe it is time we extended our database abstraction layer.
I recommend we create the following extra functions :
1. db_create_table($tablename, $columns); // columns is an associative array with the 'name' => 'type'
Why 'name' => 'type'? I'd think that 'name' => 'foo', 'type' => 'foo', 'default' => 0, and so on would be a beter way to capture all the extra stuff necessary. Chx makes a good point, though, that data column types differing between implementations is one of the ugly bits. It'd be odd to set up our own 'drupal-esque' data types and map them to db specific types in the function. --Jeff
On 11 May 2006, at 9:41 PM, Jeff Eaton wrote:
Chx makes a good point, though, that data column types differing between implementations is one of the ugly bits. It'd be odd to set up our own 'drupal-esque' data types and map them to db specific types in the function. That's what the abstraction layer is there for.
we specify integer, longtext, shortext blah .. and the abstraction layer changes that into whatever the equivalent is for that database type. ie: varchar() and text in mysql / postgres. Choose _SENSIBLE_ types, _FOR US_ and then change it into whatever works for each database. This would give us consistency in how tables are defined. -- Adrian Rossouw Drupal developer and Bryght Guy http://drupal.org | http://bryght.com
That's what the abstraction layer is there for.
we specify integer, longtext, shortext blah .. and the abstraction layer changes that into whatever the equivalent is for that database type.
ie: varchar() and text in mysql / postgres.
Choose _SENSIBLE_ types, _FOR US_ and then change it into whatever works for each database.
This would give us consistency in how tables are defined.
As I think about it, I believe you're right. --Jeff
On 11 May 2006, at 9:58 PM, Jeff Eaton wrote:
This would give us consistency in how tables are defined.
As I think about it, I believe you're right. Perhaps unit tests will help us weed out the dodgy non-standard sql that sometimes gets used, and then we can add more supported db types to our stack? (without breaking our backs supporting them)
I suppose that's one benefit to coding for mysql (the lowest common denominator) -- Adrian Rossouw Drupal developer and Bryght Guy http://drupal.org | http://bryght.com
Adrian Rossouw wrote:
Perhaps unit tests will help us weed out the dodgy non-standard sql that sometimes gets used, and then we can add more supported db types to our stack? (without breaking our backs supporting them)
I suppose that's one benefit to coding for mysql (the lowest common denominator)
Except, mysql really isn't the lowest common denominator. They have a spate of non-standard SQL extensions that are widely and popularly used -- mostly due to history. It'd be nice to get folks to use more standard, portable SQL so that we could support more db types reliably. What's the method to get there? Unit tests? Dev documentation? An SQL audit before CVS commit? ..chrisxj
On 12 May 2006, at 12:26 AM, Chris Johnson wrote:
It'd be nice to get folks to use more standard, portable SQL so that we could support more db types reliably. What's the method to get there? Unit tests? Dev documentation? An SQL audit before CVS commit?
It requires unit tests imo. Even core has a smattering of non standard sql, that only works because we could define functions with postgres. -- Adrian Rossouw Drupal developer and Bryght Guy http://drupal.org | http://bryght.com
Adrian Rossouw wrote:
we specify integer, longtext, shortext blah .. and the abstraction layer changes that into whatever the equivalent is for that database type.
ie: varchar() and text in mysql / postgres.
Choose _SENSIBLE_ types, _FOR US_ and then change it into whatever works for each database.
Exactly! (makes note to self: engage brain before typing next time) ..chrisxj
My choice would be to map them to PHP native type names.
On 11 May 2006, at 9:36 PM, Karoly Negyesi wrote:
Ah yes. And between 'character variable' of postgres and 'varchar' of mysql, which one ?
? what do you mean ? -- Adrian Rossouw Drupal developer and Bryght Guy http://drupal.org | http://bryght.com
On Thu, 2006-05-11 at 21:45 +0200, Adrian Rossouw wrote:
On 11 May 2006, at 9:36 PM, Karoly Negyesi wrote:
Ah yes. And between 'character variable' of postgres and 'varchar' of mysql, which one ?
? what do you mean ?
Couldn't we just be agnostic and use the ANSI SQL type names? Although that would make our nomenclature lean closer to PostGreSql's. I think someone implementing Ingres would be more familiar with the ANSI type names than mysql.
On May 11, 2006, at 3:36 PM, Karoly Negyesi wrote:
On Thu, 11 May 2006 20:31:32 +0200, Adrian Rossouw <adrian@bryght.com> wrote:
1. db_create_table($tablename, $columns); // columns is an associative array with the 'name' => 'type'
Ah yes. And between 'character variable' of postgres and 'varchar' of mysql, which one ?
The last time I checked (about two or three days ago?), PostgreSQL accepted column definitions using 'varchar' just fine... According to http://www.postgresql.org/docs/7.2/static/datatype.html varchar is an alias for character varying. Now, there might be problems with blob fields... Ricky
On 11 May 2006, at 10:16 PM, Richard Morse wrote:
The last time I checked (about two or three days ago?), PostgreSQL accepted column definitions using 'varchar' just fine...
Except it uses exactly the same storage mechanism as text, except it has an extra constraint check. For our uses, text is always the correct type. -- Adrian Rossouw Drupal developer and Bryght Guy http://drupal.org | http://bryght.com
On 11 May 2006, at 11:04 PM, Adrian Rossouw wrote:
The last time I checked (about two or three days ago?), PostgreSQL accepted column definitions using 'varchar' just fine...
Except it uses exactly the same storage mechanism as text, except it has an extra constraint check.
For our uses, text is always the correct type.
And text is also not our issue. -- Adrian Rossouw Drupal developer and Bryght Guy http://drupal.org | http://bryght.com
Karoly Negyesi wrote:
On Thu, 11 May 2006 20:31:32 +0200, Adrian Rossouw <adrian@bryght.com> wrote:
Now that we have .install files for modules, I believe it is time we extended our database abstraction layer.
I recommend we create the following extra functions :
1. db_create_table($tablename, $columns); // columns is an associative array with the 'name' => 'type'
Ah yes. And between 'character variable' of postgres and 'varchar' of mysql, which one ?
Recent version of postgres accept 'varchar' as a synonym for 'character varying' but does mysql accept the latter? If not, use 'varchar'. ..chrisxj
On Thursday 11 May 2006 18:19, Chris Johnson wrote:
Recent version of postgres accept 'varchar' as a synonym for 'character varying' but does mysql accept the latter? If not, use 'varchar'.
MySQL accepts CHARACTER VARYING just fine. I'm pretty sure that's the official syntax from the SQL standard as well. Scott -- ------------------------------------------------------------------------------- Syscrusher (Scott Courtney) Drupal page: http://drupal.org/user/9184 syscrusher at 4th dot com Home page: http://4th.com/
2006/5/11, Adrian Rossouw <adrian@bryght.com>:
Now that we have .install files for modules, I believe it is time we extended our database abstraction layer.
True, it should be sufficient to define a table structure only once in the install file. I recommend we create the following extra functions :
1. db_create_table($tablename, $columns); // columns is an associative array with the 'name' => 'type' 3. db_drop_table($tablename); 3. db_create_index($tablename, $columns); // columns is an array of column names, or just a single column. 4. db_drop_index($tablename, $columns); 5. db_add_column($tablename, $column, $type); // PGSQL already has a similar function, but it isn't in both systems. 6. db_drop_column($tablename, $column);
These functions are a useful addition, but I am not sure if the developer that defines tables for his module should need to use them. An alternative for the install system could be that the structure of the tables is defined in a xml file that can be validated before it is processed by the install system. Kind regards, John Pulles http://mappingwidgets.sourceforge.net | carto module
The're useful when the structure of a table evolves over time -- for example, version 1.45 of module foo adds an index for better performance. YOu can change the original definition, but you'll need these additional functions to write the update_x() function. --Jeff -----Original Message----- From: John Pulles [mailto:john.pulles@gmail.com] Sent: Thursday, May 11, 2006 3:57 PM To: development@drupal.org Subject: Re: [development] Extend database abstraction layer,to include table creation. These functions are a useful addition, but I am not sure if the developer that defines tables for his module should need to use them. An alternative for the install system could be that the structure of the tables is defined in a xml file that can be validated before it is processed by the install system.
2006/5/11, Jeff Eaton <jeff@viapositiva.net>:
The're useful when the structure of a table evolves over time -- for example, version 1.45 of module foo adds an index for better performance. YOu can change the original definition, but you'll need these additional functions to write the update_x() function.
Probably a 'diff' can be made to determine the difference between the current tables (if they are present) and the updated definition. The install/update system would then process the differences.
ot if it requires module-specific logic to convert data to a new format, or migrate old records to a new schema. Seriously, we just got the _install() and _update_x() hooks in place and they're working really well. The last thing we need is a completely different mechanism for updating being shoved into place, driven by a mess of 'intelligent' code that assumes it knows best. ;) --Jeff -----Original Message----- From: John Pulles [mailto:john.pulles@gmail.com] Sent: Thursday, May 11, 2006 4:17 PM To: development@drupal.org Subject: Re: [development] Extend database abstraction layer,to include table creation. 2006/5/11, Jeff Eaton <jeff@viapositiva.net>: The're useful when the structure of a table evolves over time -- for example, version 1.45 of module foo adds an index for better performance. YOu can change the original definition, but you'll need these additional functions to write the update_x() function. Probably a 'diff' can be made to determine the difference between the current tables (if they are present) and the updated definition. The install/update system would then process the differences.
On 11 May 2006, at 10:57 PM, John Pulles wrote:
These functions are a useful addition, but I am not sure if the developer that defines tables for his module should need to use them. An alternative for the install system could be that the structure of the tables is defined in a xml file that can be validated before it is processed by the install system.
no. no xml. xml is incredibly complex, and totally overkill for this. Our system will be closer to how rails does it updates. -- Adrian Rossouw Drupal developer and Bryght Guy http://drupal.org | http://bryght.com
Op donderdag 11 mei 2006 20:31, schreef Adrian Rossouw:
Now that we have .install files for modules, I believe it is time we extended our database abstraction layer.
I recommend we create the following extra functions :
db_fetch_all() This "whiling" over the db_fetch_object is driving me nuts :) Bèr
Op vrijdag 12 mei 2006 10:58, schreef Bèr Kessels:
Op donderdag 11 mei 2006 20:31, schreef Adrian Rossouw:
Now that we have .install files for modules, I believe it is time we extended our database abstraction layer.
I recommend we create the following extra functions :
db_fetch_all() This "whiling" over the db_fetch_object is driving me nuts :)
Money mouth and that stuff: from helpers.module (still needs testing here before I commit this) /** * Returns an array with all objects from a query * Does not do a rewrite sql for you! * Call similar to db_query. */ function db_fetch_all_as_objects($query) { $results = array(); $args = func_get_args(); array_shift($args); $res = db_query($query, $args); while ($row = db_fetch_object($res)) { $results[] = $row; } return $results; } /** * Returns an array with all arrays from a query * Does not do a rewrite sql for you! * Call similar to db_query. */ function db_fetch_all_as_arrays($query) { $results = array(); $args = func_get_args(); array_shift($args); $res = db_query($query, $args); while ($row = db_fetch_array($res)) { $results[] = $row; } return $results; }
On Friday 12 May 2006 04:42, Bèr Kessels wrote:
db_fetch_all() This "whiling" over the db_fetch_object is driving me nuts :)
Money mouth and that stuff: from helpers.module (still needs testing here before I commit this)
function db_fetch_all_as_objects($query) {
function db_fetch_all_as_arrays($query) {
Related to this: http://drupal.org/node/53488 I'm planning on adding those db utility functions. As per the question I asked in the thread, should I be looking to add those to helper.module rather than core somewhere? I'm just wary of people not even knowing they exist. (Please reply in the issue, too, so that it's easier to track. Thanks.) -- Larry Garfield AIM: LOLG42 larry@garfieldtech.com ICQ: 6817012 "If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it." -- Thomas Jefferson
Bèr Kessels wrote:
db_fetch_all() This "whiling" over the db_fetch_object is driving me nuts :)
Uggh. Adding extra loops because you don't like 'while' is nothing more than a performance hit that is unnecessary.
On 12 May 2006, at 5:03 PM, Earl Miles wrote:
Uggh. Adding extra loops because you don't like 'while' is nothing more than a performance hit that is unnecessary.
Not to mention a memory drain. The only place I could see something like this being useful is everywhere we do : $result = db_query('something'); while ($data = db_fetch_array($result) { $return[$data['some_key']] = $data; } AND NOTHING ELSE. And i don't think 4 (really 3 lines) of code is that much of a schlepp. -- Adrian Rossouw Drupal developer and Bryght Guy http://drupal.org | http://bryght.com
Adrian Rossouw wrote:
The only place I could see something like this being useful is everywhere we do :
$result = db_query('something'); while ($data = db_fetch_array($result) { $return[$data['some_key']] = $data; }
AND NOTHING ELSE.
Even then, chances are you have some kind of logic done, even in this simple of loop (for example, what is 'some_key'? the node ID? the user ID? the free tagging term?). A 'get all the db stuff into an array' function just means instead of doing: while ($data = db_fetch_array($result) { ... } you're doing: foreach ($data as $key => $value) { ... } Same difference, except you end up looping twice. :P -Angie
On 12 May 2006, at 7:01 PM, Angela Byron wrote:
Same difference, except you end up looping twice. :P
except for lookups. where you end up doing : print ($data[$key); ie: not loops. -- Adrian Rossouw Drupal developer and Bryght Guy http://drupal.org | http://bryght.com
The only place I could see something like this being useful is everywhere we do :
$result = db_query('something'); while ($data = db_fetch_array($result) { $return[$data['some_key']] = $data; }
AND NOTHING ELSE.
Of course. That's why Ber gave function name called fetch_all(). You use it when you need it. I can't understand why someone would start making noise on the list about this. You use it if you need it. That's all.
Moshe Weitzman wrote:
The only place I could see something like this being useful is everywhere we do :
$result = db_query('something'); while ($data = db_fetch_array($result) { $return[$data['some_key']] = $data; }
AND NOTHING ELSE.
Of course. That's why Ber gave function name called fetch_all(). You use it when you need it. I can't understand why someone would start making noise on the list about this. You use it if you need it. That's all.
Well, except that people who aren't quite familiar with what's going on will think that it's easier and use it in the wrong place.
Of course. That's why Ber gave function name called fetch_all(). You use it when you need it. I can't understand why someone would start making noise on the list about this. You use it if you need it. That's all.
Well, except that people who aren't quite familiar with what's going on will think that it's easier and use it in the wrong place.
Pople might misuse it is not a justification for omitting code from core. Building a collection from a db recordset an extremely common pattern and including this convenience function reduces code and makes it more readable. Do you think that improper instances of this will get into core? No chance. It won't get into any of the well reviewed contrib modules either. So what if people misuse a function in rarely used contrib module? Thats likely the least of its worries. -- moshe weitzman weitzman@tejasa.com
moshe weitzman wrote:
Pople might misuse it is not a justification for omitting code from core. Building a collection from a db recordset an extremely common pattern and including this convenience function reduces code and makes it more readable. Do you think that improper instances of this will get into core? No chance. It won't get into any of the well reviewed contrib modules either. So what if people misuse a function in rarely used contrib module? Thats likely the least of its worries.
Agreed. But going back to my point, how do we know what field to set the array key on? Key on the first field selected? Or scrap the idea of hashes and just chuck them into a numeric array, knowing that in some (most?) cases you'll need to loop through it again to make the hash what you want? It would be nice for someone who is in support of a db_fetch_all() function to maybe grep through core/contrib looking for examples of this and come up with a sane default behaviour. -Angie
On Fri, May 12, 2006 2:44 pm, Angela Byron said:
moshe weitzman wrote:
Pople might misuse it is not a justification for omitting code from core. Building a collection from a db recordset an extremely common pattern and including this convenience function reduces code and makes it more readable. Do you think that improper instances of this will get into core? No chance. It won't get into any of the well reviewed contrib modules either. So what if people misuse a function in rarely used contrib module? Thats likely the least of its worries.
Agreed. But going back to my point, how do we know what field to set the array key on? Key on the first field selected? Or scrap the idea of hashes and just chuck them into a numeric array, knowing that in some (most?) cases you'll need to loop through it again to make the hash what you want? It would be nice for someone who is in support of a db_fetch_all() function to maybe grep through core/contrib looking for examples of this and come up with a sane default behaviour.
-Angie
Also from my day job, where I wrote a Drupal-inspired db wrapper that we're about to stop using anyway (long story), I had something along these lines: $options = db_get_keyed("SELECT field1, field2 FROM mytable ... "); Poof. One line to get a key/value set that's already perfectly prepared to drop into a select box. Yes, all these little utilities can be misused, but that doesn't mean they can't also be very well used. I'll be writing Drupal equivalents (see the issue I posted earlier in this thread for where I'm starting, and for some implementation suggestions) as I have time to do so, because they really are useful. --Larry Garfield
Op vrijdag 12 mei 2006 22:24, schreef Larry Garfield:
One line to get a key/value set that's already perfectly prepared to drop into a select box.
Woa, I was just building a "select_for_select" function. This sounds soo much like it. (http://api.rubyonrails.com/classes/ActionView/Helpers/FormOptionsHelper.html...) And it makes me think: with all the discussion going on: is the contrib a good place to maintain a helpers.module? To maintain a growing set of library functions for Drupal? Would a distribution, completely separate fron drupal core be a better place? Really, there seems to be a good reason against every single function and parameter of a function within Drupal... and they are very good reasons. For the people outing the reasons... Bèr
On 12 May 2006, at 10:24 PM, Larry Garfield wrote:
$options = db_get_keyed("SELECT field1, field2 FROM mytable ... ");
function db_fetch_keyed_arrays($query, $key) { $result = db_query($query); while ($array = db_fetch_array($result) { $ret[$array[$key]] = $array; } return $ret; } function db_fetch_keyed_objects($query, $key) { $result = db_query($query); while ($array = db_fetch_object($result) { $ret[$array[$key]] = $array; } return $ret; } or something like that. -- Adrian Rossouw Drupal developer and Bryght Guy http://drupal.org | http://bryght.com
On Friday 12 May 2006 15:44, Angela Byron wrote:
Agreed. But going back to my point, how do we know what field to set the array key on? Key on the first field selected?
The standard behavior in other libraries I've seen, such as PEAR, is to have the first selected field become the key. Scott -- ------------------------------------------------------------------------------- Syscrusher (Scott Courtney) Drupal page: http://drupal.org/user/9184 syscrusher at 4th dot com Home page: http://4th.com/
moshe weitzman wrote:
Of course. That's why Ber gave function name called fetch_all(). You use it when you need it. I can't understand why someone would start making noise on the list about this. You use it if you need it. That's all. Well, except that people who aren't quite familiar with what's going on will think that it's easier and use it in the wrong place.
Pople might misuse it is not a justification for omitting code from core. Building a collection from a db recordset an extremely common pattern and including this convenience function reduces code and makes it more readable. Do you think that improper instances of this will get into core? No chance. It won't get into any of the well reviewed contrib modules either. So what if people misuse a function in rarely used contrib module? Thats likely the least of its worries.
Larry's and Moshe's arguments have convinced me. I retract my -1 and make it a +1. ..chrisxj
Regarding performance, given that creating tables is such an infrequent thing, and even when done, it only affect a few tables, the performance cost of the new abstraction layer is negligible. I am sort of conflicted on this new abstraction layer thing. I agree that will make things much easier for everyone, and hence has merit. However, unless we go totally SQL-less (i.e. no one can write direct SQL in Drupal modules, think ORM, e.g. Active Record), this will only take part of the issue (database portability) away, and not all of it. People can still write non-portable SQL, although the table creation part was taken care of. So, this may give a false sense of total abstraction, while we do not have it yet. For an alternate view on abstraction (that I do not fully support mind you, I think abstraction has merits), read Jeremy Zawodny's Database Abstraction Layers Must Die. http://jeremy.zawodny.com/blog/archives/002194.html His main points are: 1. With abstraction layers, performance cannot be gained. 2. Changing databases is never easy for a large site.
On Saturday 13 May 2006 12:06, Khalid B wrote:
http://jeremy.zawodny.com/blog/archives/002194.html
His main points are:
1. With abstraction layers, performance cannot be gained.
Depends on your performance measurement. Abstraction layers are not about improving system performance; they're about improving developer performance. We could make Drupal a hundred times faster if we recoded it in hand-tweaked x86 assembler. It would take us a few years to get something even get something marginally useful, but it would be faster because we'd have eliminated a dozen abstraction layers! (PHP, C, SQL, etc.) I'd rather burn a few cycles than a few days or weeks of my time. Hardware costs less than I do.
2. Changing databases is never easy for a large site.
Depends on your codebase, and if you planned ahead. -- Larry Garfield AIM: LOLG42 larry@garfieldtech.com ICQ: 6817012 "If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it." -- Thomas Jefferson
On 5/14/06, Larry Garfield <larry@garfieldtech.com> wrote:
On Saturday 13 May 2006 12:06, Khalid B wrote:
http://jeremy.zawodny.com/blog/archives/002194.html
His main points are:
1. With abstraction layers, performance cannot be gained.
Depends on your performance measurement. Abstraction layers are not about improving system performance; they're about improving developer performance.
We could make Drupal a hundred times faster if we recoded it in hand-tweaked x86 assembler. It would take us a few years to get something even get something marginally useful, but it would be faster because we'd have eliminated a dozen abstraction layers! (PHP, C, SQL, etc.) I'd rather burn a few cycles than a few days or weeks of my time. Hardware costs less than I do.
2. Changing databases is never easy for a large site.
Depends on your codebase, and if you planned ahead.
Let me play devil's advocate here ... The problem with an abstraction layer for the database that we are proposing is that : 1. It is not complete, since engine specific SQL statements can be embedded, and hence portability will be lost in this case. There is a false sense of portability that is there. 2. It is a lowest common denominator thing, and hence is dumbed down. 3. When you want to do things in the backend because you do not want to retreive the data in the middle tier (PHP) and incurr a performance penalty, you often have engine specific syntax (think of UNIX_TIME functions for example, date intervals, ...etc.) End Devil's Advocate mode. I am not against the database creation stuff that Adrian proposed. What I see is that in the future we may move to total abstraction. If we realize that we can no longer optimize for a specific engine without losing portability, OR that we allow it at the risk of losing portability, then we should be fine. The problem is where we are under the illusion that we have something (portability and performance) but we are not.
On 14 May 2006, at 5:08 PM, Khalid B wrote:
If we realize that we can no longer optimize for a specific engine without losing portability,
What's wrong with doing : db_create_table('blah' // etc. if ($globals['db_type'] == 'type') { // optimise the table for that db type. } It's still a lot less code than duplicating every single line of every single schema for every single db type. When we look at our usage patterns up to now, that ends up being the exception and not the rule. -- Adrian Rossouw Drupal developer and Bryght Guy http://drupal.org | http://bryght.com
If we realize that we can no longer optimize for a specific engine without losing portability,
What's wrong with doing :
db_create_table('blah' // etc.
if ($globals['db_type'] == 'type') { // optimise the table for that db type. }
It's still a lot less code than duplicating every single line of every single schema for every single db type.
When we look at our usage patterns up to now, that ends up being the exception and not the rule.
Nothing wrong with that. And that enforces my point that there is no practical absolute abstraction. If a PostgreSQL guy writes this and does not bother with writing a MySQL part, then that piece of code is now PostgreSQL specific and no longer abstracted. As I said, nothing wrong with that AS LONG AS WE REALIZE that by allowing this, we wander off into engine specific code again ...
On 14 May 2006, at 6:59 PM, Khalid B wrote:
Nothing wrong with that. And that enforces my point that there is no practical absolute abstraction.
I know that. There is no practical absolute abstraction. We can however abstract what happens in 99% of the cases. There also always chance that certain databases need to have somewhat separate updates too, such as the case where we want to select distinct rows for some form of conversion. -- Adrian Rossouw Drupal developer and Bryght Guy http://drupal.org | http://bryght.com
On Friday 12 May 2006 15:27, moshe weitzman wrote:
Pople might misuse it is not a justification for omitting code from core. Building a collection from a db recordset an extremely common pattern and including this convenience function reduces code and makes it more readable.
+1 Every time we can turn this: do_a_query() while (not_done_with_rows) { put_another_row_into_array } return rows_array into this: return fetch_all_from_query() we have made some Drupal module smaller, faster to compile, easier to read, and more maintainable. It's not a matter of whether programmers are *able* to use a while() loop -- it's a matter of whether they should have to code the same loop pattern again and again and again. I would go even further, to suggest three other very common usage patterns that should get dedicated functions: 1. Execute a query that will return exactly one row, and return that row into an object. If the query returns multiple rows, return only the first one. Example use case: SELECT * FROM {node} WHERE nid=1234; Suggested function signature: $object = db_query_row($sql [, $params]) 2. Execute a query that will return exactly one column of one row, and return that data value as a simple variable of mixed type. Example use case: SELECT COUNT(*) FROM {node} WHERE type='story'; Suggested function signature: $mixed = db_query_value($sql [, $params]) 3. Execute a query that will return exactly one column of an arbitrary number of rows, and return those values as an integer-subscripted array. Example use case: SELECT DISTINCT type FROM {node} ORDER BY type; Suggested functoin signature: $array = db_query_column($sql [, $params]) Aside from the reduction in code size of all the modules that use the new functions, there is an additional advantage. Right now, there is no way to tell the database layer that one is finished with a query, to free up the result set resources. Since these functions -- as well as the db_fetch_all() function previously discussed by others -- all have *internal* knowledge of when the underlying SQL query is finished, they can transparently release the internal result set resource before they return. The PEAR code, which is GPL, could be easily adapted to provide these functions. I'm willing to volunteer to do it, though it sounds as if there are others who are eager to work on this project. Scott -- ------------------------------------------------------------------------------- Syscrusher (Scott Courtney) Drupal page: http://drupal.org/user/9184 syscrusher at 4th dot com Home page: http://4th.com/
2. Execute a query that will return exactly one column of one row, and return that data value as a simple variable of mixed type.
Example use case: SELECT COUNT(*) FROM {node} WHERE type='story';
Suggested function signature: $mixed = db_query_value($sql [, $params])
We already have this: http://drupaldocs.org/api/head/function/db_result
Op vrijdag 12 mei 2006 19:18, schreef Moshe Weitzman:
$result = db_query('something'); while ($data = db_fetch_array($result) { $return[$data['some_key']] = $data; }
If you read the code, you will find that I do nothing more then this. I do not call this "noise". IMO this is all about "shortcuts", If Drupal "forces" us to write: $result = db_query('something'); while ($data = db_fetch_array($result) { $return[$data['some_key']] = $data; } twenty times. Then IMO Drupal Does a very Bad Job. That is all. I presented a solution to an itch that itches me. Nothing more nothing less. Feel free to call it "a memory drain". But also feel free to call it "usefull". And above all:These endless and *extremely* annoying discussions are the one and only reason this is not a patch for core but a helper function in the herlpers module. And yes, please contribute to that. the only thing id like to see is sone "patch history" to make sure we dont end up with a complete crappy helper module. Bèr
Earl Miles wrote:
Bèr Kessels wrote:
db_fetch_all() This "whiling" over the db_fetch_object is driving me nuts :)
Uggh. Adding extra loops because you don't like 'while' is nothing more than a performance hit that is unnecessary.
Yeah, I'm pretty -1 on the idea of adding these to the database abstraction. If one is coding PHP for Drupal, one should be a competent enough programmer to deal with a while loop over a database fetch. ..chrisxj
On Fri, May 12, 2006 1:28 pm, Chris Johnson said:
Earl Miles wrote:
Bèr Kessels wrote:
db_fetch_all() This "whiling" over the db_fetch_object is driving me nuts :)
Uggh. Adding extra loops because you don't like 'while' is nothing more than a performance hit that is unnecessary.
Yeah, I'm pretty -1 on the idea of adding these to the database abstraction. If one is coding PHP for Drupal, one should be a competent enough programmer to deal with a while loop over a database fetch.
..chrisxj
It's not a matter of competence, but of convenience. In my non-Drupal work (which currently is far more time than my Drupal work, sadly), I need to get a series of query result rows as objects first, then pass them around, surprisingly often. Same for getting just one column of a result set as an array. Sure, that's 4-5 lines of simple code, but it's the same 5 lines 100 times. If you're doing that several times, that's a clear sign that you should be abstracting it. It makes the code easier to read later, too. --Larry Garfield
Op vrijdag 12 mei 2006 21:12, schreef Larry Garfield:
If you're doing that several times, that's a clear sign that you should be abstracting it. It makes the code easier to read later, too.
This is called DNRY Do not repeat yourself. As soon as you have written a single line of code twice, you have done something wrong! Maybe not now, but certainly along the road. Bèr
On Friday 12 May 2006 17:01, Bèr Kessels wrote:
Op vrijdag 12 mei 2006 21:12, schreef Larry Garfield:
If you're doing that several times, that's a clear sign that you should be abstracting it. It makes the code easier to read later, too.
This is called DNRY Do not repeat yourself.
As soon as you have written a single line of code twice, you have done something wrong! Maybe not now, but certainly along the road.
Bèr
I refer to it as the Asimov Rule: The most unlikely number in the universe is 2. (If you write the same thing a second time, odds are you'll be writing it a 3rd, 4th, and 97th time, so generalize NOW before you go further.) -- Larry Garfield AIM: LOLG42 larry@garfieldtech.com ICQ: 6817012 "If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it." -- Thomas Jefferson
James Walker wrote:
On 12-May-06, at 4:58 AM, Bèr Kessels wrote:
db_fetch_all()
+1 .. but use with care, of course... lest you much all your RAM ;)
Totally. Just as well that we don't store files in the database tables! ;) I have this type of wrapper function in a couple of modules that connect to an external db's, although I don't use it 100% of the time it is a nice shortcut to have available.
On 11 May 2006, at 8:31 PM, Adrian Rossouw wrote:
Now that we have .install files for modules, I believe it is time we extended our database abstraction layer.
I recommend we create the following extra functions :
Now the next question is, is anybody interested in working on this. This will help making the installer get in a lot quicker, by reducing the amount of cross db development we need to do. I'm currently busy helping vlado with the template system stuff, and also working on the meta-data / dependency system. While I don't mind working on this, it is something that could run in parallel with other efforts, and would really help Drupal on a lot of fronts. -- Adrian Rossouw Drupal developer and Bryght Guy http://drupal.org | http://bryght.com
Adrian Rossouw schrieb:
On 11 May 2006, at 8:31 PM, Adrian Rossouw wrote:
Now that we have .install files for modules, I believe it is time we extended our database abstraction layer.
I recommend we create the following extra functions :
Now the next question is, is anybody interested in working on this. This will help making the installer get in a lot quicker, by reducing the amount of cross db development we need to do.
I just started working on a implentation in database.mysql.inc. Think I'll be able to publish a patch on the day after tomorrow ;) best regards, Franz Heinzmann --- frando@xcite-online.de xcite-online.de
On 12 May 2006, at 2:55 PM, Frando wrote:
I just started working on a implentation in database.mysql.inc. Think I'll be able to publish a patch on the day after tomorrow ;)
Awesome. Thanks man =). -- Adrian Rossouw Drupal developer and Bryght Guy http://drupal.org | http://bryght.com
See http://drupal.org/node/63049 for a implentation of the proposed functions. There is some documentation available in the code and I wrote some usage examples in my comment in the issue tracker. best regards, frando --- Franz Heinzmann frando@xcite-online.de Adrian Rossouw schrieb:
On 12 May 2006, at 2:55 PM, Frando wrote:
I just started working on a implentation in database.mysql.inc. Think I'll be able to publish a patch on the day after tomorrow ;)
Awesome. Thanks man =).
-- Adrian Rossouw Drupal developer and Bryght Guy http://drupal.org | http://bryght.com
On 12 May 2006, at 11:37, Adrian Rossouw wrote:
Now the next question is, is anybody interested in working on this. This will help making the installer get in a lot quicker, by reducing the amount of cross db development we need to do.
I'm currently busy helping vlado with the template system stuff, and also working on the meta-data / dependency system. While I don't mind working on this, it is something that could run in parallel with other efforts, and would really help Drupal on a lot of fronts.
Personally, I'd like to see the template stuff go in first so it's great to see you guys focus on that first. I also want us to look at chx's node type patch (see patch queue) which implements an extremely light version of the CCK / flexinode module. It will help us get rid of the pseudo-duplicate-node- types. If some people could help test and review that patch, that would be awesome. I already gave it a couple reviews, and things are almost usable, it seems. :-) -- Dries Buytaert :: http://www.buytaert.net/
Adrian Rossouw wrote:
On 11 May 2006, at 8:31 PM, Adrian Rossouw wrote:
Now that we have .install files for modules, I believe it is time we extended our database abstraction layer.
I recommend we create the following extra functions :
Now the next question is, is anybody interested in working on this. This will help making the installer get in a lot quicker, by reducing the amount of cross db development we need to do.
I'm interested in working on the database abstraction layer. ..chrisxj
hi On 5/12/06, Chris Johnson <chris@tinpixel.com> wrote:
Adrian Rossouw wrote:
On 11 May 2006, at 8:31 PM, Adrian Rossouw wrote:
Now that we have .install files for modules, I believe it is time we extended our database abstraction layer.
I recommend we create the following extra functions :
Now the next question is, is anybody interested in working on this. This will help making the installer get in a lot quicker, by reducing the amount of cross db development we need to do.
I'm interested in working on the database abstraction layer.
i am interested in working -- <name> balachandar muruganantham</name> <Yahoo!> mbchandar</Yahoo!> <Hotmail> mbchandar</Hotmail> <blog> http://www.balachandar.net/blog</blog> <web>http://www.balachandar.net</web> <talk> http://www.expertstalk.org</talk> <shop>http://www.chennaishopping.com</shop>
On 11 May 2006, at 20:31, Adrian Rossouw wrote:
Now that we have .install files for modules, I believe it is time we extended our database abstraction layer.
I recommend we create the following extra functions :
1. db_create_table($tablename, $columns); // columns is an associative array with the 'name' => 'type' 3. db_drop_table($tablename); 3. db_create_index($tablename, $columns); // columns is an array of column names, or just a single column. 4. db_drop_index($tablename, $columns); 5. db_add_column($tablename, $column, $type); // PGSQL already has a similar function, but it isn't in both systems. 6. db_drop_column($tablename, $column);
The installer that is coming in, will be converting the database.*sql files into a system.install file, and with these functions, we can collapse ALL THREE SCHEMA FILES, into a single, much simpler file.
Can't we move forward without these functions? It looks like we are introducing more and more dependencies to that makes it harder to move the install system forward. While an additional database layer (SQL is already an abstraction layer) makes it easier to port Drupal to other database systems, it makes it harder to understand what is going on. It is a lot less accessible to people that are new to Drupal, but that do have a SQL background. So personally, I'm not all that convinced that these functions are a good idea ... I, for one, find it much easier to read an SQL statement than some (new) Drupal-specific table definition. I don't want to learn or use a such definition language. Such functions make the database scheme less transparent. -- Dries Buytaert :: http://www.buytaert.net/
I, for one, find it much easier to read an SQL statement than some (new)
So true for SQL statements. But alas, the wise people of the ANSI SQL committee forgot to standardize DDL. Hence the need.
There certainly is a cost for this extra abstraction layer. But the beneits are substantial, and IMO, outweight the costs you've identified. Expanding on my response in this issue (http://drupal.org/node/63049) - automatically gives us pgsql compatibility for most modules. Only those that use non standard sql are broken. - paves a clear path toward fixing the slight security problem we introduced with 4.7. Since the install and update systems regularly create and drop tables, an admin has to give the DB user those permissions. For 4.8 we want the admin to have the option of defining a one $db_url for usual queries and another for database definition queries. Database definition queries will go through the aforementioned functions and at that point we can challenege the user for uid=1 credentials or something else. - specific to the installer, adrian mentions that our three schema files unify to one. also, consider how much code gets thrown out when you take every update in every contrib module and remove the pgsql branch. We will be defining updates only once. So, it might be true that installer should proceed without this. But The benefits are substantial IMO and is a project worth doing IMO. It isn't that hard either. -moshe On 5/12/06 12:00 PM, "Dries Buytaert" <dries.buytaert@gmail.com> wrote:
On 11 May 2006, at 20:31, Adrian Rossouw wrote:
Now that we have .install files for modules, I believe it is time we extended our database abstraction layer.
I recommend we create the following extra functions :
1. db_create_table($tablename, $columns); // columns is an associative array with the 'name' => 'type' 3. db_drop_table($tablename); 3. db_create_index($tablename, $columns); // columns is an array of column names, or just a single column. 4. db_drop_index($tablename, $columns); 5. db_add_column($tablename, $column, $type); // PGSQL already has a similar function, but it isn't in both systems. 6. db_drop_column($tablename, $column);
The installer that is coming in, will be converting the database.*sql files into a system.install file, and with these functions, we can collapse ALL THREE SCHEMA FILES, into a single, much simpler file.
Can't we move forward without these functions? It looks like we are introducing more and more dependencies to that makes it harder to move the install system forward.
While an additional database layer (SQL is already an abstraction layer) makes it easier to port Drupal to other database systems, it makes it harder to understand what is going on. It is a lot less accessible to people that are new to Drupal, but that do have a SQL background. So personally, I'm not all that convinced that these functions are a good idea ...
I, for one, find it much easier to read an SQL statement than some (new) Drupal-specific table definition. I don't want to learn or use a such definition language. Such functions make the database scheme less transparent.
-- Dries Buytaert :: http://www.buytaert.net/
On 12 May 2006, at 11:13 PM, Moshe Weitzman wrote:
So, it might be true that installer should proceed without this. But The benefits are substantial IMO and is a project worth doing IMO. It isn't that hard either.
Like I said. This patch isn't going to stop the install system from going in, but it will make the install system patch at least ~1000 lines smaller. -- Adrian Rossouw Drupal developer and Bryght Guy http://drupal.org | http://bryght.com
Op vrijdag 12 mei 2006 18:00, schreef Dries Buytaert:
I, for one, find it much easier to read an SQL statement than some (new) Drupal-specific table definition. I don't want to learn or use a such definition language. Such functions make the database scheme less transparent.
The agility! wonderfull ;) Serious: What Drupal needs above all, is not some "Higher Language To Talk To Lower Languages", but a way to make stuff easier. IMveryHO forms api surpassed its goal in this: What is easier: calling form_weight() or building an object-from-drupal-specific-arrays? Point is clear. If we go for some DB abstraction layer, we should really, IMnsHO look at Active Record (PHP stuff at http://phplens.com/phpeverywhere/?q=node/view/228), wich does not take SQL away from developers but makes it easier to use. A Big Difference, IMO. Whether we go for AR itself or some AR library, the central point should IMO be: "make it easier for developers to build sites". Wich is far from "make a system in such a way that developers are pushed to build technical better system". Drupal, IMO is walking slowly towards the latter the way its going now. A pity, because it does not make things better. Only "technical better". Bèr
On 13-mei-2006, at 0:17, Bèr Kessels wrote:
Op vrijdag 12 mei 2006 18:00, schreef Dries Buytaert:
I, for one, find it much easier to read an SQL statement than some (new) Drupal-specific table definition. I don't want to learn or use a such definition language. Such functions make the database scheme less transparent.
The agility! wonderfull ;)
Serious: What Drupal needs above all, is not some "Higher Language To Talk To Lower Languages", but a way to make stuff easier.
IMveryHO forms api surpassed its goal in this: What is easier: calling form_weight() or building an object-from-drupal-specific-arrays? Point is clear.
If we go for some DB abstraction layer, we should really, IMnsHO look at Active Record (PHP stuff at http://phplens.com/phpeverywhere/?q=node/view/228), wich does not take SQL away from developers but makes it easier to use. A Big Difference, IMO.
Whether we go for AR itself or some AR library, the central point should IMO be: "make it easier for developers to build sites".
Wich is far from "make a system in such a way that developers are pushed to build technical better system". Drupal, IMO is walking slowly towards the latter the way its going now. A pity, because it does not make things better. Only "technical better".
Bèr
Mark Janssen mark@praseodym.net
I'm going to do some Bèr's praise here. I'm usually really strict about the DNRY personally. Though I use 3 instances as a clue that I'm going to need to split the code into a function. Continuing that train of thought, how many time have you had to do some sort of INSERT/UPDATE switch in you drupal code? I think Bèr is right on in suggesting we consider something like AR. It's a little more OO than drupal has been in the past do to overhead concerns but I'm not sure that applies here. Big +1 from me. James On 5/12/06, Bèr Kessels <ber@webschuur.com> wrote:
Op vrijdag 12 mei 2006 18:00, schreef Dries Buytaert:
I, for one, find it much easier to read an SQL statement than some (new) Drupal-specific table definition. I don't want to learn or use a such definition language. Such functions make the database scheme less transparent.
The agility! wonderfull ;)
Serious: What Drupal needs above all, is not some "Higher Language To Talk To Lower Languages", but a way to make stuff easier.
IMveryHO forms api surpassed its goal in this: What is easier: calling form_weight() or building an object-from-drupal-specific-arrays? Point is clear.
If we go for some DB abstraction layer, we should really, IMnsHO look at Active Record (PHP stuff at http://phplens.com/phpeverywhere/?q=node/view/228), wich does not take SQL away from developers but makes it easier to use. A Big Difference, IMO.
Whether we go for AR itself or some AR library, the central point should IMO be: "make it easier for developers to build sites".
Wich is far from "make a system in such a way that developers are pushed to build technical better system". Drupal, IMO is walking slowly towards the latter the way its going now. A pity, because it does not make things better. Only "technical better".
Bèr
On Friday 12 May 2006 18:06, James Gilliland wrote:
I'm going to do some Bèr's praise here. I'm usually really strict about the DNRY personally. Though I use 3 instances as a clue that I'm going to need to split the code into a function.
Continuing that train of thought, how many time have you had to do some sort of INSERT/UPDATE switch in you drupal code?
http://drupal.org/node/53488 :-) I hope to get to it this weekend, if someone can give me a hint as to which method would be better to use. :-) If time permits, I'll see about doing some of these other db-nicetiy functions, too. -- Larry Garfield AIM: LOLG42 larry@garfieldtech.com ICQ: 6817012 "If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it." -- Thomas Jefferson
On 13 May 2006, at 00:17, Bèr Kessels wrote:
Serious: What Drupal needs above all, is not some "Higher Language To Talk To Lower Languages", but a way to make stuff easier.
IMveryHO forms api surpassed its goal in this: What is easier: calling form_weight() or building an object-from-drupal-specific-arrays? Point is clear.
I agree. While Drupal becomes more powerful, it also becomes more difficult to develop for. Drupal 4.7's new forms API is a prime example. It is obviously great in terms of security and flexibility, but at the same time, it is also _much_ harder to use than the old form API. What does that mean? Well, that some people can make really fancy forms but that the majority of the people will find it more difficult to make basic forms. This is somewhat problematic as we need more people that are good Drupal developers. There is such a strong demand for good Drupal developers, yet which each new version, we add more barriers as a side effect of making Drupal more powerful. As a result, we'll get many more users, but relatively fewer developers. And that's a big problem. For most of us eliminating the various SQL schemas makes perfect sense. After all, most of us are expert Drupal developers, and as such, an incremental improvement is easy enough to deal with. However, for new Drupal developers, who are not intimate with Drupal's code, this just increases the barrier. Why did you end up with Drupal to begin with? Because it had an extremely powerful API for every single problem? Or because it was clean code, easy to get into and make work? The web is built by millions of individuals, many of which are amateurs. They continuously update, tweak and rebuild their websites. We want Drupal to remain accessible for them. Hence, the challenge is to make Drupal more powerful _AND_ easier to develop for. This requires that we question certain development directions and look at them through the eyes of amateurs. http://buytaert.net/complexity-is-a-disease http://buytaert.net/why-php-and-not-java -- Dries Buytaert :: http://www.buytaert.net/
Dries Buytaert wrote:
On 13 May 2006, at 00:17, Bèr Kessels wrote:
Serious: What Drupal needs above all, is not some "Higher Language To Talk To Lower Languages", but a way to make stuff easier.
IMveryHO forms api surpassed its goal in this: What is easier: calling form_weight() or building an object-from-drupal-specific-arrays? Point is clear.
I agree. While Drupal becomes more powerful, it also becomes more difficult to develop for.
Drupal 4.7's new forms API is a prime example. It is obviously great in terms of security and flexibility, but at the same time, it is also _much_ harder to use than the old form API. What does that mean? Well, that some people can make really fancy forms but that the majority of the people will find it more difficult to make basic forms.
I disagree. It isn't that much harder to use. The separation of validation and submit action into separate functions makes the code much more readable and easier to see what is going. I am currently upgrading my evaluation module, which has huge forms, and really appreciate this.
This is somewhat problematic as we need more people that are good Drupal developers. There is such a
We recently got some very nice additions to our developer crowd.
strong demand for good Drupal developers, yet which each new version, we add more barriers as a side effect of making Drupal more powerful.
I think this is only a matter of perception. You (as I was) aren't yet fully comfy with the new forms API and thus think that everybody will find it more difficult. For people who are new to it, they will just read the (excellent!) docs and should be able to make the usual forms within a few minutes.
As a result, we'll get many more users, but relatively fewer developers. And that's a big problem.
We will always get less new developers than new users.
For most of us eliminating the various SQL schemas makes perfect sense. After all, most of us are expert Drupal developers, and as such, an incremental improvement is easy enough to deal with. However, for new Drupal developers, who are not intimate with Drupal's code, this just increases the barrier.
Here's a point where I agree. I wouldn't want to add a load of new db functions like the proposed db_fetch_all_*. This just confuses matters and people don't know which to use when. However, I'd be in favour of functions such as db_add_column or db_create_table. I also would like to bring this old much of mine to everybody's attention again (http://drupal.org/node/17656). Any new database abstraction that we add should be able to address the subject of this patch.
Why did you end up with Drupal to begin with? Because it had an extremely powerful API for every single problem? Or because it was clean code, easy to get into and make work?
Because it had web based translation and was rather conservative in its demands wrt software versions. :p Also, I thought I would eventually be able what PHP is.
The web is built by millions of individuals, many of which are amateurs. They continuously update, tweak and rebuild their websites. We want Drupal to remain accessible for them.
Do we? I certainly want them to be able to use Drupal but I'd appreciate if they'd keep their hands out of the code if they aren't programmers. This only makes for nasty support cases.
Hence, the challenge is to make Drupal more powerful _AND_ easier to develop for. This requires that we question certain development directions and look at them through the eyes of amateurs.
Call it "budding PHP programmers" and I am with you, but we shouldn't use Drupal as a teaching toy for amateurs. Cheers, Gerhard
Dries wrote:
We want Drupal to remain accessible for them.
"Gerhard Killesreiter" wrote:
Do we?
My impression is that you do not wish it be accessible.
I certainly want them to be able to use Drupal but I'd appreciate if they'd keep their hands out of the code if they aren't programmers. This only makes for nasty support cases.
There currently is no way to use Drupal without modifying code. Period. The ease of use score for Drupal would have to be considered very low, compared to other CMS tools. It's range of functionality is far greater, of course, but not for the average, download-and-install user, or even the generic site user, who doesn't even manage the Drupal installation. The chief barrier to fully marrying Drupal is the ongoing code-writing that must be done: even themes are written in PHP, and once you add a module, you must immediately begin PHP training. How do you propose that any Drupal user (not developer, just a user) "keep their hands out of the code"? -- Gary
Gary (Lists) wrote:
Dries wrote:
We want Drupal to remain accessible for them.
"Gerhard Killesreiter" wrote:
Do we?
My impression is that you do not wish it be accessible.
Hadn't you promised to unsubscribe from this list?
I certainly want them to be able to use Drupal but I'd appreciate if they'd keep their hands out of the code if they aren't programmers. This only makes for nasty support cases.
There currently is no way to use Drupal without modifying code. Period.
I obviously disagree. And no, themes don't really count as code.
The ease of use score for Drupal would have to be considered very low, compared to other CMS tools.
Some consider it high compared to the likes of wordpress and mambo/joomla. Granted, at least wordpress isn't really a CMS.
It's range of functionality is far greater, of course, but not for the average, download-and-install user, or even the generic site user, who doesn't even manage the Drupal installation.
Right.
The chief barrier to fully marrying Drupal is the ongoing code-writing that must be done: even themes are written in PHP, and once you add a module, you must immediately begin PHP training.
I still disagree. xtemplate is supported for 4.7, albeit in contrib.
How do you propose that any Drupal user (not developer, just a user) "keep their hands out of the code"?
By just not tampering with stuff which isn't meant to be tampered with if you don't know how to. I don't see a problem in setting up a site with plain Drupal and only creating a custom theme. You could even only modify the CSS that comes with one of the core themes and replace the image files if your standards on uniqueness aren't that high. Cheers, Gerhard
Dries wrote:
We want Drupal to remain accessible for them.
Gerhard wrote:
Do we?
I wrote:
My impression is that you do not wish it be accessible.
Gerhard wrote:
Hadn't you promised to unsubscribe from this list?
You continue to make my point. After receiving a half dozen off-list apologies for your behavior (a real shame that others felt the need to distance your behavior from Drupal's reputation), I believe that I'll just filter your posts to the trash. (And I would encourage you to exercise the same freedom, beginning at your leisure.) This way, I can receive valuable reading from civilized people and avoid the "angry penguins". When one is engaged in a conflict with another person, and the other person simply refuses respect and reason, there is no safe option but to disengage from that person. Perhaps there are valid explanations for your diminished social capacity -- either cultural, psychological or genetic -- but they are of no interest to me. You do not threaten me, Gerhard, and I simply refuse to be bullied by you. Feel free to use your time and valuable human energy on more fruitful tasks. I know that I will. Sadly, and with mind always open, -- Gary
Gary (Lists) wrote:
There currently is no way to use Drupal without modifying code. Period.
This is patently untrue. Only my very first Drupal implementation has modifications to core code, and I later learned how to do those things I wanted without core code. It certainly helps to be able to add code via modules, but that is not the same thing.
I want to jump back a bit and make a quick point. Coming in just recently and doing a *lot* of converting old fapi to new, the new api is a lot easier to understand and work with for me. For one thing I don't have to worry about the the args for each func or even one func. The keys are descriptive and tell you what your adding and are common among most form elements. All it required was a basic understanding of html form which should be a requirement anyways My point is fresh eyes see things different. Also, I have several installs with no coding what so ever. Every time I'd come to merlin with "I think I'm going to code a module to do X", he'd tell me to look at module Y he or someone else had already written. That aside and back on topic. I know drupal is a scratch your own itch sort of system but its growing fast. I think a lot of people here have been hinting at this but pretty soon the firebird guys are going to be wanting to post compatibility patches to core. And then(pull out those buzzword bingo cards and get ready) someone's boss is going to ask if they can run an "enterprise" ready install of drupal on oracle. Suddently our update functions are 200lines long instead of 50 and our .install files are 10k. I'm probably exagerating a little but those seem like some serious maintainability issues. Also, I have a good grasp of SQL, both mySQL and plSQL(not really pgSQ: yet), but
Comment.find_by_id(12) Comment.title = "Foo Bar" Comment.save!
is actually easier to read for me. Maybe that's just a design practice modules should use more but I think there's room to take some of the SQL leg work of the drupal dev. James
Op zaterdag 13 mei 2006 18:56, schreef Earl Miles:
This is patently untrue. Only my very first Drupal implementation has modifications to core code, and I later learned how to do those things I wanted without core code.
I just did a very quick CVS diff over my 21 sites multisite installation: Core is omdified, but only because of security reasons (I dont want PHP eval stuff). But 17 of the 21 sites contain one or more modified modules. 6 of the 21 contain modules that I wrote specially for them 15 of 21 contain newly built or modified themes. Conclusion: I am NOT able to deploy a Drupal site without touching PHP or hacking up the system. It depends on what you define as "Drupal". If that is only core, then its possible to run a site unhacked. If Drupal is "the whole PHP clunk" then its nearly impossible to "just run it". Good news is that Drupal is PHP. And PHP is scripting, thus easy to modify. Bad news is that Drupal core is getting more and more complex. In the past one could simply add an if() around some pievce of code if you wanted to eliminate a certain form element, but we now need quite difficult (yet higher level) FAPI alter hooks. I think we should recognise (a lot of devels already do that) that Drupal is not just a Ready To Run system, but a developers platform. And that facilitating these hackers by providing easy core and usefull methods/apis could be a main target for a lot of people. Bèr
Bèr Kessels wrote:
Op zaterdag 13 mei 2006 18:56, schreef Earl Miles:
This is patently untrue. Only my very first Drupal implementation has modifications to core code, and I later learned how to do those things I wanted without core code.
I just did a very quick CVS diff over my 21 sites multisite installation: Core is omdified, but only because of security reasons (I dont want PHP eval stuff). But 17 of the 21 sites contain one or more modified modules. 6 of the 21 contain modules that I wrote specially for them 15 of 21 contain newly built or modified themes.
You are making these changes because you can. You skills help you to run better sites. But even if you had not the skills you yould still use Drupal. Sure, your sites would lack a feature here and there, but that's not the point. The point is that Drupal "out of the box" works for a lot of people and you don't need to know PHP to set up a site which already has a lot of features. Cheers, Gerhard
"Gary (Lists)" wrote:
There currently is no way to use Drupal without modifying code. Period.
schreef Earl Miles:
This is patently untrue. Only my very first Drupal implementation has modifications to core code, and I later learned how to do those things I wanted without core code.
"Bèr Kessels" wrote:
I just did a very quick CVS diff over my 21 sites multisite installation: Core is omdified, but only because of security reasons (I dont want PHP eval stuff). But 17 of the 21 sites contain one or more modified modules. 6 of the 21 contain modules that I wrote specially for them 15 of 21 contain newly built or modified themes.
Conclusion: I am NOT able to deploy a Drupal site without touching PHP or hacking up the system.
I believe that you make my point very well. These numbers are useful. And my point is not to be taken as "just a complaint", for it is not. It's a real barrier, most especially, to keeping things up to date and implementing new features as they become recommended.
I think we should recognise (a lot of devels already do that) that Drupal is not just a Ready To Run system, but a developers platform.
And this is the most important distinction that could be made. This could really stand to be addressed, even from those loudly advocating a "Who Cares" attitude on this list. Those folks (or that folk) really makes his own point: If you don't want people messing about in the code, then make the system useful to those who would rather not, anyway. The best way to increase the slope of the adoption and retention curve (for any product, actually) is to make the barrier to entry very low and to provide incentive to retain. Open source does not need to mean "must open source". -- Gary
Op maandag 15 mei 2006 14:34, schreef Gary (Lists):
And my point is not to be taken as "just a complaint", for it is not. It's a real barrier, most especially, to keeping things up to date and implementing new features as they become recommended.
Op zondag 14 mei 2006 14:45, schreef Gerhard Killesreiter:
You are making these changes because you can. You skills help you to run better sites. But even if you had not the skills you yould still use Drupal. Sure, your sites would lack a feature here and there, but that's not the point. The point is that Drupal "out of the box" works for a lot of people and you don't need to know PHP to set up a site which already has a lot of features.
I am not complaining. I am saying two things: 1) Drupal is very powerfull (mostly becuase of its architecture) for modificated websites. There is absolutely no way that I could hack Joomja, or Nuke in such an easy way (I used both a lot, so its not just a matter of knowing one app better). Which is was my reason for moving to Drupal. 2) Becuase Drupal has this power, and this great "feature", we have a real gem at hand! We should not forget that a lot of people might use Drupal for this very reason too. Focussing only on end-user improvements, is IMO bad. That is my main point. Dries points out in several blog posts and mailinglists mails that the low "hop on level" is a good thing in Drupal. I wanted to add to his points the fact that it is easy to hack Drupal. Hacking your stuff is not bad. Because IMO getting a good site up n Running you simply cannot do without it. From the Lets keep Drupal Hack Friendly dept. Bèr
I started using Drupal 4.2 in summer of 2003, and 4.3/4.4 was out before I went live in Jan 2004, so I upgraded to that. The first iteration of live Drupal sites I used was a heavily modified multisite install, even the theme was a heavily modified pre-Bluemarine theme. Later, I switched to stock Pushbutton with a logo. Over the years, I found that my modifications to core are less and less with every release that comes out. Part of it is that bugs I file tend to get fixed, although slower than I would like, but it eventually gets done. Part of it is I want to have the least modifications possible, so that I would not have to merge my changes with every release. Part of it is that Drupal is getting more flexible and powerful with less code and bloat ... So, I think we are on the right track here, at least in my experience.
Bèr Kessels wrote:
Hacking your stuff is not bad. Because IMO getting a good site up n Running you simply cannot do without it.
I still think this is an unfair characterization. You can do amazing things with Drupal without hacking the core, you just have to know exactly how to do it sometimes. As I said, I have several installations without core hacking involved. There are some special needs, right now, that might still involve a little core hacking here and there but a lot of these hacks that people do are just as likely to be unnecessary. And characterizing Drupal as requiring core hacking because you have some special needs is unfair to the entire community who CAN make Drupal useful without hacking the core.
Earl Miles wrote:
Bèr Kessels wrote:
Hacking your stuff is not bad. Because IMO getting a good site up n Running you simply cannot do without it.
... characterizing Drupal as requiring core hacking because you have some special needs is unfair to the entire community who CAN make Drupal useful without hacking the core.
Doesn't Robert Douglass' book on Drupal give lots of examples of configuring a Drupal site to all kinds of interesting things, without any code hacking?
On Mon, 2006-05-15 at 08:34 -0400, Gary (Lists) wrote:
"Gary (Lists)" wrote:
There currently is no way to use Drupal without modifying code. Period.
schreef Earl Miles:
This is patently untrue. Only my very first Drupal implementation has modifications to core code, and I later learned how to do those things I wanted without core code.
"Bèr Kessels" wrote:
I just did a very quick CVS diff over my 21 sites multisite installation: Core is omdified, but only because of security reasons (I dont want PHP eval stuff). But 17 of the 21 sites contain one or more modified modules. 6 of the 21 contain modules that I wrote specially for them 15 of 21 contain newly built or modified themes.
Conclusion: I am NOT able to deploy a Drupal site without touching PHP or hacking up the system.
I believe that you make my point very well. These numbers are useful.
And my point is not to be taken as "just a complaint", for it is not. It's a real barrier, most especially, to keeping things up to date and implementing new features as they become recommended.
Umm I've put together some awesome asset management tools for magazines that respect editorial and production workflows using drupal, without coding more than a few patches for broken modules. that aren't yet released..
This is somewhat problematic as we need more people that are good Drupal developers. There is such a
We recently got some very nice additions to our developer crowd.
At any point in time, we had a nice addition of developers. That doesn't mean there is enough talent available.
strong demand for good Drupal developers, yet which each new version, we add more barriers as a side effect of making Drupal more powerful.
I think this is only a matter of perception. You (as I was) aren't yet fully comfy with the new forms API and thus think that everybody will find it more difficult. For people who are new to it, they will just read the (excellent!) docs and should be able to make the usual forms within a few minutes.
It's not just a matter of perception. At least a dozen people told me they got flabbergasted by the new forms API.
The web is built by millions of individuals, many of which are amateurs. They continuously update, tweak and rebuild their websites. We want Drupal to remain accessible for them.
Do we? I certainly want them to be able to use Drupal but I'd appreciate if they'd keep their hands out of the code if they aren't programmers. This only makes for nasty support cases.
Funny. You just mentioned you didn't know any PHP or MySQL when you started using Drupal ... -- Dries Buytaert :: http://www.buytaert.net/
Dries Buytaert wrote:
This is somewhat problematic as we need more people that are good Drupal developers. There is such a
We recently got some very nice additions to our developer crowd.
At any point in time, we had a nice addition of developers. That doesn't mean there is enough talent available.
What qualifies as "enough"? Drupal is a growing project and sure we could need more Drupal coders. But it isn't that we wouldn't get new code. You already added a couple new features to HEAD and 4.7 is only two weeks old. There are a lot of patches flying around and soon I will have to get extra patches for 4.7 because the code changed so much.
strong demand for good Drupal developers, yet which each new version, we add more barriers as a side effect of making Drupal more powerful.
I think this is only a matter of perception. You (as I was) aren't yet fully comfy with the new forms API and thus think that everybody will find it more difficult. For people who are new to it, they will just read the (excellent!) docs and should be able to make the usual forms within a few minutes.
It's not just a matter of perception. At least a dozen people told me they got flabbergasted by the new forms API.
Oh, I was too. Because I was used to the old ways. It took some time - and the process isn't finished - to get used to the new ways. I am quite sure that 2/3 of your dozen people were people who were used to the old string based functions and had not really investigated the new forms. Of course, I am not yet 100% confortable with it, but I was always a slow learner. ;)
The web is built by millions of individuals, many of which are amateurs. They continuously update, tweak and rebuild their websites. We want Drupal to remain accessible for them.
Do we? I certainly want them to be able to use Drupal but I'd appreciate if they'd keep their hands out of the code if they aren't programmers. This only makes for nasty support cases.
Funny. You just mentioned you didn't know any PHP or MySQL when you started using Drupal ...
Right. I first had tried to build a web site builder in bash and AWK and found it didn't work too well. Then I looked for CMSes in FORTRAN. Didn't find any and resorted to learn another programming language. But I wouldn't say that I didn't have any programming experience. Cheers, Gerhard
in general, i totally agree with the thrust of what dries is saying about trying to keep drupal easier to develop for. however, i also think adrian is right in this specific case that such a table creation and modification abstraction layer would be a good thing. On May 13, 2006, at 2:51 AM, Dries Buytaert wrote:
For most of us eliminating the various SQL schemas makes perfect sense. After all, most of us are expert Drupal developers, and as such, an incremental improvement is easy enough to deal with. However, for new Drupal developers, who are not intimate with Drupal's code, this just increases the barrier. ... This requires that we question certain development directions and look at them through the eyes of amateurs.
i'm not exactly an amateur, but i didn't know *any* SQL syntax as of 5 months ago when i first tried setting up a drupal site for my band. for me, the kind of abstraction layer adrian proposed (and others expanded on) would have probably helped me get up to speed more quickly. maybe i'm in the tiny minority of potential drupal developers who aren't already SQL wizards, but who know how to write code (i didn't know php either, but the syntax is enough like perl and C and the docs are good enough that i could figure it out). however, from my perspective as still something of a drupal novice, i don't think this would have slowed me down or deterred me in any way. i'm about to face the prospect of setting up 2 very important sites (at least important to me *grin*) that will have to run on postgres for reasons beyond my control. i know *nothing* about postgres, and i'd really rather i didn't have to port any contrib modules to it. if this abstraction layer will help eliminate that problem, i'm all for it. furthermore, i've spent quite a few hours already dealing with patches that needed to be re-written since i missed another spot where i should have changed a schema, dealt with merge conflicts caused by this sort of thing, etc. the schema duplication and DB update code is some of the least elegant (and hardest to maintain) code in all of drupal (at least the parts i've seen). 1 last point: the software i write for my day job is a huge, horribly complex, very low-level system that runs on most versions of UNIX and windoze. we've made copious use of abstraction layers over the years to hide the ugly details of various aspects of platform-specific garbage. the overwhelming majority of the code can now be written without worrying about if you're on a windoze, macos, linux, or *gasp* hpux10 machine (yeah, we've ripped out the ultrix 4.2 code by now, though it used to work there when i started). porting to a new platform mostly entails porting a small handful of the abstraction layers, not the million+ lines of code. adding new features can be done by people who don't really know anything about the trickier aspects of how solaris handles a certain system call. sure, it takes time to learn our internal APIs, but i think it's still a win over trying to learn the entire system API for ~15 different platforms. grad students trying to crank out a new daemon as a research project can get something up and running that listens on a socket (which can be authenticated with SSL, Kerberos, etc), handles TCP and UDP commands, does logging (with file locking, rotating, different severity levels, etc), traps signals, and can handle periodic timers, all with about 100 lines of code against our internal APIs. of course, drupal is facing different challenges, and most of the portability problems are handled by httpd and the php binary. however, i think there are analogies that are still relevant (especially when talking about db support). food for thought... -derek (dww) p.s. there's an old saying in computer science circles: "all problems in computer science can be solved by caching and/or adding another level of indirection." there's much truth to that.
On 13 May 2006, at 13:15, Derek Wright wrote:
in general, i totally agree with the thrust of what dries is saying about trying to keep drupal easier to develop for. however, i also think adrian is right in this specific case that such a table creation and modification abstraction layer would be a good thing.
That is the thing. I agree with Adrian as well (I can see the advantages), it's just that we need to be careful and look at this from a beginner's point of view. We should avoid turning this thing into a system that quacks like an enterprise-level CMS. In such systems, you can define database schema's using XML, but at the end of the day, they aren't used as much as Drupal. Guess why? Part of the answer is that no one can install or customize such system without hiring a consultant. That's not where we want to go.
i'm not exactly an amateur, but i didn't know *any* SQL syntax as of 5 months ago when i first tried setting up a drupal site for my band. for me, the kind of abstraction layer adrian proposed (and others expanded on) would have probably helped me get up to speed more quickly. maybe i'm in the tiny minority of potential drupal developers who aren't already SQL wizards, but who know how to write code (i didn't know php either, but the syntax is enough like perl and C and the docs are good enough that i could figure it out). however, from my perspective as still something of a drupal novice, i don't think this would have slowed me down or deterred me in any way.
How can you understand the table definition proposed by Adrian (see below), if you don't know any SQL? I don't think this gets you up to speed any more quickly. Quite the contrary, you'd first have to learn SQL and then you have to figure out how this Drupal specific definition format maps onto it. Make no mistake, a Drupal-specific definition language is no excuse for not having to learn MySQL. It does add an additional step to the learning curve! db_create_table('client_system', array( 'cid' => array('type' => 'int', 'NOT NULL' => TRUE, 'PRIMARY KEY' => TRUE), 'name' => array('type' => 'short text', 'NOT NULL', 'default' => '', , 'PRIMARY KEY' => TRUE), 'type' => array('type' => 'short text', 'NOT NULL', 'default' => ''), )); Hundreds of books have been written about PHP and MySQL. As a newbie, you can buy these books and understand what Drupal's MySQL schemas mean. If we add an extra abstraction layer, these books are going to be less useful. Hence, we added a barrier. It does, however, help you write portable code, but that isn't something most people are concerned about. Newbies want to write code that works, and that they can understand. Being able to understand something is very rewarding/motivating. Portability is not their main concern. IMO. I'm not saying that the database definition function is a bad thing or that we should drop it on the floor. We have to carefully evaluate whether the advantages (portability) outweight the drawbacks (less developers). All I can say, is that, as a programmer, I can write SQL faster than I can write db_create_table() definitions. Plus, I value the transparency of the "raw" SQL statements; at least I know _exactly_ what is going on under the hood. Here is something to think about (I'm still trying to figure out the best way to formulate this): The net effect of creating abstracting layers for everything is that you're building a new programming language on top of the existing languages (eg. PHP and MySQL). At some point, you'll loose some of the underlying languages' advantages (eg. available documentation, talent pool, transparency). You see this happen in the Java world. Because of all the layers (EJBs, Struts, JSTLs, JSPs, Beans, CMP, BMP, JAXM), J2EE started to live a life on its own. Being a "regular" Java developer isn't enough to get certain jobs. -- Dries Buytaert :: http://www.buytaert.net/
Dries Buytaert wrote:
On 13 May 2006, at 13:15, Derek Wright wrote:
i'm not exactly an amateur, but i didn't know *any* SQL syntax as of 5 months ago when i first tried setting up a drupal site for my band. for me, the kind of abstraction layer adrian proposed (and others expanded on) would have probably helped me get up to speed more quickly. maybe i'm in the tiny minority of potential drupal developers who aren't already SQL wizards, but who know how to write code (i didn't know php either, but the syntax is enough like perl and C and the docs are good enough that i could figure it out). however, from my perspective as still something of a drupal novice, i don't think this would have slowed me down or deterred me in any way.
How can you understand the table definition proposed by Adrian (see below), if you don't know any SQL?
When I started to use Drupal I did know neither PHP nor SQL.
I don't think this gets you up to speed any more quickly. Quite the contrary, you'd first have to learn SQL and then you have to figure out how this Drupal specific definition format maps onto it. Make no mistake, a Drupal-specific definition language is no excuse for not having to learn MySQL. It does add an additional step to the learning curve!
No. I never learned SQL properly. I just copy and pasted the queries that I found and then modified them untill they gave me what I wanted.
db_create_table('client_system', array( 'cid' => array('type' => 'int', 'NOT NULL' => TRUE, 'PRIMARY KEY' => TRUE), 'name' => array('type' => 'short text', 'NOT NULL', 'default' => '', , 'PRIMARY KEY' => TRUE), 'type' => array('type' => 'short text', 'NOT NULL', 'default' => ''), ));
Hundreds of books have been written about PHP and MySQL. As a newbie, you can buy these books and understand what Drupal's MySQL schemas mean.
While that is true, most people don't buy these books. I think that Adrian's proposed scheme isn't harder to learn from scratch than the usual SQL queries. The only drawback is that when you learn plain SQL you can use it elsewhere too while you can't do so with Adrian's abstraction layer.
If we add an extra abstraction layer, these books are going to be less useful. Hence, we added a barrier.
If nobody buys these books, this is a moot point. :p it is also easy to add a conversion utility that shows a user how the query above would look in plain SQL (in whatever version they want to have it!).
It does, however, help you write portable code, but that isn't something most people are concerned about. Newbies want to write code that works, and that they can understand. Being able to understand something is very rewarding/motivating. Portability is not their main concern. IMO.
Right. But as a project, it should be _our_ concern. As a module author I would certainly appreciate if all my modules would work with pgsql (and maybe other backends) without further worries.
I'm not saying that the database definition function is a bad thing or that we should drop it on the floor. We have to carefully evaluate whether the advantages (portability) outweight the drawbacks (less developers).
Any developer worth the name should be easily able to understand this scheme if he has prior knowledge of SQL. If he hasn't then it doesn't matter (to us) if he learns plain SQL or our db abstraction layer.
All I can say, is that, as a programmer, I can write SQL faster than I can write db_create_table() definitions.
Use an editor which allows you to insert templates. :p
Plus, I value the transparency of the "raw" SQL statements; at least I know _exactly_ what is going on under the hood.
That's true, but as a said a convertor is easy to write and will already be somewhere in Drupal's code. I think that most serious code editors could also have templates that call a function to convert any API expression on the fly.
Here is something to think about (I'm still trying to figure out the best way to formulate this):
The net effect of creating abstracting layers for everything is that you're building a new programming language on top of the existing languages (eg. PHP and MySQL).
Right.
At some point, you'll loose some of the underlying languages' advantages (eg. available documentation, talent pool, transparency).
True.
You see this happen in the Java world. Because of all the layers (EJBs, Struts, JSTLs, JSPs, Beans, CMP, BMP, JAXM), J2EE started to live a life on its own. Being a "regular" Java developer isn't enough to get certain jobs.
I don't think I'd apply for regular plain-PHP jobs or maybe typo3 jobs either. To sum it up: For the Drupal project having a truely portable database API is invaluable. That it inconveniences some people is a given, but I'd accept that. What Adrian proposes is much more readable than what I've seen on other abstraction stuff. Cheers, Gerhard
On 12 May 2006, at 17:50, Gerhard Killesreiter wrote:
Hundreds of books have been written about PHP and MySQL. As a newbie, you can buy these books and understand what Drupal's MySQL schemas mean.
While that is true, most people don't buy these books. I think that Adrian's proposed scheme isn't harder to learn from scratch than the usual SQL queries. The only drawback is that when you learn plain SQL you can use it elsewhere too while you can't do so with Adrian's abstraction layer.
No. If no one would buy these books, there wouldn't be as many available.
I'm not saying that the database definition function is a bad thing or that we should drop it on the floor. We have to carefully evaluate whether the advantages (portability) outweight the drawbacks (less developers).
Any developer worth the name should be easily able to understand this scheme if he has prior knowledge of SQL. If he hasn't then it doesn't matter (to us) if he learns plain SQL or our db abstraction layer.
No. If you believe that is true, then the following holds as well: "Any developer worth the name should be easily able to understand PostgreSQL if he has prior knowledge of (My)SQL". -- Dries Buytaert :: http://www.buytaert.net/
Dries Buytaert wrote:
On 12 May 2006, at 17:50, Gerhard Killesreiter wrote:
Hundreds of books have been written about PHP and MySQL. As a newbie, you can buy these books and understand what Drupal's MySQL schemas mean.
While that is true, most people don't buy these books. I think that Adrian's proposed scheme isn't harder to learn from scratch than the usual SQL queries. The only drawback is that when you learn plain SQL you can use it elsewhere too while you can't do so with Adrian's abstraction layer.
No. If no one would buy these books, there wouldn't be as many available.
Well, I admit you got a point there. I always wondered who buys all these computer books and how many of the books just end up sitting in shelves and try to impress the casual visitor. :p Do you own a book on PHP? If yes, did you buy it yourself? If yes, why? The closest to buying a computer book I ever got was to print the AWK manual and to bind it. And no, I am not writing this because I am trying to impress anybody.
I'm not saying that the database definition function is a bad thing or that we should drop it on the floor. We have to carefully evaluate whether the advantages (portability) outweight the drawbacks (less developers).
Any developer worth the name should be easily able to understand this scheme if he has prior knowledge of SQL. If he hasn't then it doesn't matter (to us) if he learns plain SQL or our db abstraction layer.
No. If you believe that is true, then the following holds as well: "Any developer worth the name should be easily able to understand PostgreSQL if he has prior knowledge of (My)SQL".
Yes, of course, the differences aren't that big. I only always ask the people who I know actually use PostgreSQL because I am too lazy to look it up, and they don't need to. I have no interest in PostgreSQL, so I don't learn it. But I am confident I could if I wanted to. Cheers, Gerhard
http://cvs.sourceforge.net/viewcvs.py/easymod/sql_parser/root/includes/sql/ Look who committed that... sound familiar, heh?
How can you understand the table definition proposed by Adrian (see below), if you don't know any SQL? I don't think this gets you up to speed any more quickly. Quite the contrary, you'd first have to learn SQL and then you have to figure out how this Drupal specific definition format maps onto it. Make no mistake, a Drupal-specific definition language is no excuse for not having to learn MySQL. It does add an additional step to the learning curve!
Considering that there already is an existing DB astraction layer and has been for x versions, I'm not entirely sure why there's a concern for adding "table creation" to it as well. The beginner user is already subjected to this vaunted learning curve through the use of pager queries (and associated eccentricities), db_rewrite_sql, table prefixing etc. IMO, Adrian's proposal just completes this process of abstraction. I also do not believe that the 'fiddlers' in question use the SQL in the .install files to understand the DB structure. They use PHPMyAdmin/PHPPgAdmin to do so (and get a neatly formatted tabular represetation of said structure) and very likely don't give a rat's hind-quarter as to how it got there :) Moreover, we are already subjecting the beginner programmer to a more complex abstration layer via the use of the forms API and this is probably only going to get more complex. Forms are fundamentally more important to the "tinkerer" than SQL (install) queries. Just as a layman programmer can ditch the entire forms API and use standard HTML forms, he/she can also just use straight SQL queries if he/she wants to. The immediately apparent advantages of using the proposed functions: 1. Simplify updates.inc: Some of the functions proposed are already present, but are currently only being used for pgSQL (oddly enough). 2. Improve consistency between pgSQL and MySQL: At present, the two structures lack congruity - for e.g. the locales_target table in pgSQL has a UNIQUE lid whereas the equivalent MySQL table does not. Similarly, there are discrepancies between UNSIGNED fields and so on.. 3. Improve pgSQL support in contrib: Currently, a healthy (sic) percentage of modules either don't provide pgSQL database files (in cases where they haven't migrated to the .install system) or leave the 'pgsql' section empty in their .install files. These install functions will effectively nullify this issue; pgSQL users won't need to know MySQL syntax and vice versa. 4. Make thing easier if/as/when we begin to (officially) support Oracle/MSSQL/Sybase/... I'm sure osinet/fgm who (IIRC) uses Firebird will appreciate this. 5. Improve code brevity. 6. GOTO 1 :P w.r.t. point 2: IMO changes to the .??sql files should only be made by (the committer) applying an update to a fresh database and then taking a database dump. The database should be of the same version as in Drupal's minimum requirements. In terms of readability, I think something along the lines of the fapi formatting will make things less daunting: db_create_table('client_system', array( 'cid' => array( 'type' => 'int', 'NOT NULL' => TRUE, 'PRIMARY KEY' => TRUE), 'name' => array( 'type' => 'short text', 'NOT NULL' => TRUE, 'default' => '', 'PRIMARY KEY' => FALSE), 'type' => array( 'type' => 'short text', 'NOT NULL' => TRUE, 'default' => ''))); If a newbie can't understand the above as it is, then he/she very likely won't understand it when it's written in SQL either (and vice versa heh). Users are also free to view the .??sql file. The primary precaution that needs to be taken is in the choice of semantics for contentious keywords. In my opinion, the positives outweigh any negatives. Thanks, -K P.S. -1 for any plans to ditch .sql files altogether.
Dries Buytaert wrote:
How can you understand the table definition proposed by Adrian (see below), if you don't know any SQL? I don't think this gets you up to speed any more quickly. Quite the contrary, you'd first have to learn SQL and then you have to figure out how this Drupal specific definition format maps onto it. Make no mistake, a Drupal-specific definition language is no excuse for not having to learn MySQL. It does add an additional step to the learning curve!
This is a very good point, and something I don't think a lot of us have considered while proposing this. But I have a question... would the introduction of db_create_table() mean removing the ability to just continue copy/pasting PHPMyAdmin dumps into db_query()? Or are we simply proposing some additional API functions for developers who wish to write portable SQL code in an easy way? It seems to me we could have the best of both worlds by not changing the current behaviour of db_query(), and instead just introducing some additional API calls for more "advanced" developers who understand MySQL but maybe don't know PostgreSQL and would like to write portable code could do so without needing to install PostgreSQL and read the whole manual there (which is another learning curve :)). -Angie
On Saturday 13 May 2006 10:17, Angela Byron wrote:
Dries Buytaert wrote:
How can you understand the table definition proposed by Adrian (see below), if you don't know any SQL? I don't think this gets you up to speed any more quickly. Quite the contrary, you'd first have to learn SQL and then you have to figure out how this Drupal specific definition format maps onto it. Make no mistake, a Drupal-specific definition language is no excuse for not having to learn MySQL. It does add an additional step to the learning curve!
This is a very good point, and something I don't think a lot of us have considered while proposing this.
But I have a question... would the introduction of db_create_table() mean removing the ability to just continue copy/pasting PHPMyAdmin dumps into db_query()? Or are we simply proposing some additional API functions for developers who wish to write portable SQL code in an easy way?
Precisely. Adding db_create_table() in no way needs to make db_query("CREATE TABLE...") stop working. Adding .install files hasn't made the old .mysql files suddenly not work. MANY contrib modules still use them, and they work perfectly fine. They just look silly for users because they've an extra step in installing that module. Similarly, if Joe Contrib (to abuse a theme) decides to keep using a switch statement and db_query() in his .install file, that won't break unless he's on a host where the normal db user doesn't have create table permissions, in which case we've already just broken him anyway. It's just more work for him to not use the newer functions. It's less of a difference for the user than if he were using the old .mysql files instead. And if someone else comes across such a module and is annoyed by it, it's all GPLed, so they can scratch that itch and tweak the file. That's already happened to several contrib modules, as I understand it, to add .install files. Unlike Form API, we're not breaking backward compatibility with table-manipulation functions. The old methods will still work, just be no longer the recommended way. That sounds like a win-win to me. -- Larry Garfield AIM: LOLG42 larry@garfieldtech.com ICQ: 6817012 "If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it." -- Thomas Jefferson
On 13 May 2006, at 5:17 PM, Angela Byron wrote:
But I have a question... would the introduction of db_create_table() mean removing the ability to just continue copy/pasting PHPMyAdmin dumps into db_query()? Or are we simply proposing some additional API functions for developers who wish to write portable SQL code in an easy way? They can't do that now with the install system anyway.
If you put table creation code "FOR A MODULE" into phpmyadmin, it won't update the schema versions, and your updates, when they happen. Will break. Sure, you're free to just not use the install system for that module at all, but at that point you should not be distributing your module, and it shouldn't be in drupal.org cvs for consumption by other people. Keep in mind, putting sql into phpmyadmin also doesn't to table prefixing, and all the other things a distributed module should do. If you distribute your code on drupal.org, you should be using the install system and if you are using the install system, you should be using the abstraction layer.
It seems to me we could have the best of both worlds by not changing the current behaviour of db_query(), and instead just introducing some additional API calls for more "advanced" developers who understand MySQL but maybe don't know PostgreSQL and would like to write portable code could do so without needing to install PostgreSQL and read the whole manual there (which is another learning curve :)). Nobody suggested changing db_query at all. These are some extra functions, exclusively meant for the .install files.
We already have some of these functions, but only for postgres, and these functions have cleaned up the postgres updates significantly. What it comes down to, is these functions are essentially 'theme()' functions, but for sql statements. Nothing more, nothing less. -- Adrian Rossouw Drupal developer and Bryght Guy http://drupal.org | http://bryght.com
Op zaterdag 13 mei 2006 14:50, schreef Dries Buytaert:
Hundreds of books have been written about PHP and MySQL. As a newbie, you can buy these books and understand what Drupal's MySQL schemas mean. If we add an extra abstraction layer, these books are going to be less useful. Hence, we added a barrier.
It does, however, help you write portable code, but that isn't something most people are concerned about. Newbies want to write code that works, and that they can understand. Being able to understand something is very rewarding/motivating. Portability is not their main concern. IMO.
There is a way inbetween this too. The Middle Road. And that is how Active Record works. Let us forget about OO vs non OO for a second and look at this: Comment.find_by_id(12) Comment.title = "Foo Bar" Comment.save! But you can also do: Comment.find(:first, :conditions => "id = 12") ..same as above .. And even: Comment.find_by_sql("select * from comments where id = 12") ..same as above.. Now. The point is that in your Day to Day work, you need not bother about SQL. But that is not the same as "not being allowed to use SQL". David Heinemeier Hansson: "Some object-relational mappers seek to eradicate the use of SQL entirely..." "..Active record does not. It was built on the notion that SQL is neither dirty nor bad, just verbose in the trivial cases." "... Therefore, you shouldn't feel guilgy when you use find_by_sql() to handle either performance bottlenecks or hard queries. Start out using the object-oriented interface for productivity and pleasure, and then dip beneath the surface for a close-to-the-metal experience when you need to". Which IMO is how we should treat Drupals "abstraction layer" too. Not try to pull out the SQL etc for sake of abstraction. Not making stuff more OO for the sake of portability. But only to make working on Drupal more fun, faster, and more productive. We should really try to avoid becoming a platform that you "fight against to get stuff done your way". It should be a fun and productive thing to do, working on a Drupal site. Working with Drupal should leave you all warm and fuzzy. With a "wow! this is very smart and usefull" erlebnis every hour. Instead of a "why the *** cant I just use foo bar here. Wy the *** do i need to read sqlApiLayers introductions and manuals when all I need is to store a value." I am not saying this is the case now. But I fear that if we continue rolling down the road of more complexity and more abstraction, without remaining pragmatic, we are going to loose precious developers. Bèr
Bèr Kessels schrieb:
Op zaterdag 13 mei 2006 14:50, schreef Dries Buytaert:
Hundreds of books have been written about PHP and MySQL. As a newbie, you can buy these books and understand what Drupal's MySQL schemas mean. If we add an extra abstraction layer, these books are going to be less useful. Hence, we added a barrier.
It does, however, help you write portable code, but that isn't something most people are concerned about. Newbies want to write code that works, and that they can understand. Being able to understand something is very rewarding/motivating. Portability is not their main concern. IMO.
There is a way inbetween this too. The Middle Road. And that is how Active Record works. Let us forget about OO vs non OO for a second and look at this:
Comment.find_by_id(12) Comment.title = "Foo Bar" Comment.save!
But you can also do: Comment.find(:first, :conditions => "id = 12") ..same as above ..
And even: Comment.find_by_sql("select * from comments where id = 12") ..same as above..
Now. The point is that in your Day to Day work, you need not bother about SQL. But that is not the same as "not being allowed to use SQL".
David Heinemeier Hansson: "Some object-relational mappers seek to eradicate the use of SQL entirely..." "..Active record does not. It was built on the notion that SQL is neither dirty nor bad, just verbose in the trivial cases." "... Therefore, you shouldn't feel guilgy when you use find_by_sql() to handle either performance bottlenecks or hard queries. Start out using the object-oriented interface for productivity and pleasure, and then dip beneath the surface for a close-to-the-metal experience when you need to".
Which IMO is how we should treat Drupals "abstraction layer" too.
Not try to pull out the SQL etc for sake of abstraction. Not making stuff more OO for the sake of portability. But only to make working on Drupal more fun, faster, and more productive.
We should really try to avoid becoming a platform that you "fight against to get stuff done your way". It should be a fun and productive thing to do, working on a Drupal site. Working with Drupal should leave you all warm and fuzzy. With a "wow! this is very smart and usefull" erlebnis every hour.
Instead of a "why the *** cant I just use foo bar here. Wy the *** do i need to read sqlApiLayers introductions and manuals when all I need is to store a value."
I am not saying this is the case now. But I fear that if we continue rolling down the road of more complexity and more abstraction, without remaining pragmatic, we are going to loose precious developers.
Bèr
+1. I think, ActiveRecords in drupal would just be perfect. For my last project, I used a php framework called CakePHP [1]. It's quite similar to RoR, but written in php. It implents a lot of ActiveRecords stuff, and I never created a web app faster. Especially for simple, every-day-work, for example by coding quite a simple data managment module, ActiveRecords saves not only a lot of code, but also a lot of time. I can't see any reasons against including ActiveRecords in drupal, espacially because no one will be forced to use them, but a lot of people will. best regards, frando [1] www.cakephp.org
On Saturday 13 May 2006 11:49, Bèr Kessels wrote:
There is a way inbetween this too. The Middle Road. And that is how Active Record works. Let us forget about OO vs non OO for a second and look at this:
Comment.find_by_id(12) Comment.title = "Foo Bar" Comment.save!
But you can also do: Comment.find(:first,
:conditions => "id = 12")
..same as above ..
I agree it's nice, but it's hardly a new concept. I was doing that with PEAR::DB_DataObjects well before RoR existed. We actually already have that, kinda, for nodes. node_load() and node_save(). :-) True, they don't cover everything, but could we possibly be leveraging that better? -- Larry Garfield AIM: LOLG42 larry@garfieldtech.com ICQ: 6817012 "If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it." -- Thomas Jefferson
Op zondag 14 mei 2006 08:36, schreef Larry Garfield:
True, they don't cover everything, but could we possibly be leveraging that better?
That is my whole point. Esp. since Drupal is not (and should not be, IMO) OO enough to become real Active Record. And indeed, main aim of my helpers.module is to provide a lot of these functions in a quick-to-go environment. I hope, however, that that module can be some of a stepping stone for core. We can test functions and concepts there. We can also see what stuff is used more often and what not. Popular helper functions should get a patch then for Core. (if someone finds the need to do so!) Bèr
I'm on Adrian's side as well, in terms of this debate. I think that there's EVERY reason to add this last 'missing link' to Drupal's DB abstraction layer, and that there's really no valid reason to hold it back. On 5/13/06, Dries Buytaert <dries.buytaert@gmail.com> wrote:
Hence, the challenge is to make Drupal more powerful _AND_ easier to develop for. This requires that we question certain development directions and look at them through the eyes of amateurs.
IMO, learning the DDL specifics of two different database systems is more of a barrier for new developers, than learning a simple abstraction layer ever could be. I can't speak for all developers, but personally, I've always been much more familiar with MySQL, and I've been scared and uneducated about the details of pgSQL for quite some time. I've been developing with Drupal for over a year, but only recently have I taken the time to dig a little deeper (just a little) into pgSQL - just enough to make my modules compatible with it. Most Drupal developers are only really comfortable with one system (out of MySQL and pgSQL - with the majority being on the MySQL side). Why should we have to learn another one, when a few simple extra functions in core could eliminate that learning barrier for us? This reason, combined with the other advantages of an improved abstraction layer (i.e. less duplicated SQL code, less maintenance, less chance of bugs), makes the choice a no-brainer (IMO). Cheers, Jaza.
On 13 May 2006, at 14:27, Jeremy Epstein wrote:
Hence, the challenge is to make Drupal more powerful _AND_ easier to develop for. This requires that we question certain development directions and look at them through the eyes of amateurs.
IMO, learning the DDL specifics of two different database systems is more of a barrier for new developers, than learning a simple abstraction layer ever could be. I can't speak for all developers, but personally, I've always been much more familiar with MySQL, and I've been scared and uneducated about the details of pgSQL for quite some time. I've been developing with Drupal for over a year, but only recently have I taken the time to dig a little deeper (just a little) into pgSQL - just enough to make my modules compatible with it.
The fact you didn't dig deeper into PostgreSQL until now, illustrates my point. People new to Drupal want to write code that works. They are just scratching their own itch. They want to tweak or extend Drupal, and they want it to be super easy to do. Getting the job done, and done quickly while still feeling good about it, is what sucks them into Drupal. Portability is not a major concern until they are fully sucked into Drupal development. -- Dries Buytaert :: http://www.buytaert.net/
On 5/13/06, Dries Buytaert <dries.buytaert@gmail.com> wrote:
The fact you didn't dig deeper into PostgreSQL until now, illustrates my point.
People new to Drupal want to write code that works. They are just scratching their own itch. They want to tweak or extend Drupal, and they want it to be super easy to do. Getting the job done, and done quickly while still feeling good about it, is what sucks them into Drupal. Portability is not a major concern until they are fully sucked into Drupal development.
Actually, I think it's my point that's being illustrated ;-). But then again, I would think that, since it's _my_ point! It's all a question of perception... Fact (as you said): new Drupal developers just want to write code that works, and they don't care about portability. So the only way that we're ever going to get new developers (or experienced developers who are in a hurry) to write portable code, is by forcing them to. If the quickest way for Jane Newbie to get the job done is to copy some calls to db_create_table() out of core, and to paste them into her foobar_module.install file and hack them a bit, then that's what will be done. This will take her about the same amount of time to complete, as would copying and hacking plain SQL out of core. But, the side effect will be that her install queries are database independent. The process and the learning curve for new developers will remain pretty much the same as it is now, except that instead of writing one set of plain SQL 'CREATE TABLE' queries (that will only run on MySQL), newbie_module_xyz will have one set of db_create_table() calls (that will run on MySQL or on pgSQL). And let's face it, most new developers will only need to know that ONE function - the details of which can be learned by spending 5 minutes reading the specs page for it on api.drupal.org. I don't see this as being any different from the learning barrier that already exists to support table prefixing. New developers must learn the {curly bracket} syntax before they start writing any SQL in Drupal - this is already an abstraction on top of 'plain' SQL queries. Admittedly, the new proposed functions such as db_create_table() are going to be a fair bit more complex than the prefixing syntax, but the principle is the same. Cheers, Jaza.
2006. május 13, szombat 16.04 dátummal Jeremy Epstein ezt írta:
Fact (as you said): new Drupal developers just want to write code that works, and they don't care about portability. So the only way that
The newbies only want a good documentation and examples in one place. Yesterday, I try to look for taxonomy_save_term's documentation. There's no a word about this function. Ok, experienced users are able to look inside the code to find out how it works, but I don't think that it is the best way. Newbies love to write perfect code, but if we don't learn them how they can do it and we force them, they'll be upset.
I don't see this as being any different from the learning barrier that already exists to support table prefixing. New developers must learn the {curly bracket} syntax before they start writing any SQL in Drupal
Should they read and memorize the whole Drupal Handbook to write a code? I don't think so. Did you know, the {} is only (i don't know, because when I type "curly" into the search box, I get issues, forum topic, etc but not the handbook pages) mentioned in the "How to write database independent code" . It's not about how to write db independent code. When I run through the table of contents of the handbooks, I don't see any section dedicated to how to use the db functions properly. I think, if you force the users to use special functions, you have to give them sophisticated documentation, where you tell them how and why they should use, with detailed use cases. You can't write too much. Good practice: "Multipage forms with the Forms API" (http://drupal.org/node/54753) It's a detailed tutorial with a huge code and description. Bests, -- Aries
Drupal 4.7's new forms API is a prime example. It is obviously great in terms of security and flexibility, but at the same time, it is also _much_ harder to use than the old form API. What does that mean? Well, that some people can make really fancy forms but that the majority of the people will find it more difficult to make basic forms.
The AJAX form builder, I hope, will make this easier. It will be done as a SoC project.
Dries Buytaert wrote:
For most of us eliminating the various SQL schemas makes perfect sense. After all, most of us are expert Drupal developers, and as such, an incremental improvement is easy enough to deal with. However, for new Drupal developers, who are not intimate with Drupal's code, this just increases the barrier.
I sit on the fence regarding abstraction layers. But a quick comment about new Drupal developers. The best thing for a newbie who has SQL experience (eg. me) is to have a plain english data dictionary where each table and field is described. Sure I can glean information from database.mysql, but its usefulness is limited. sime
On 13-May-06, at 5:51 AM, Dries Buytaert wrote:
On 13 May 2006, at 00:17, Bèr Kessels wrote:
Serious: What Drupal needs above all, is not some "Higher Language To Talk To Lower Languages", but a way to make stuff easier.
IMveryHO forms api surpassed its goal in this: What is easier: calling form_weight() or building an object-from-drupal-specific-arrays? Point is clear.
I agree. While Drupal becomes more powerful, it also becomes more difficult to develop for.
Drupal 4.7's new forms API is a prime example. It is obviously great in terms of security and flexibility, but at the same time, it is also _much_ harder to use than the old form API. What does that mean? Well, that some people can make really fancy forms but that the majority of the people will find it more difficult to make basic forms.
I kinda disagree here - I find the keyed array's *much* easier to read and figure out how that's gonna translate... perhaps you were the one guy who could remember the function parameter order of the old "API"?
This is somewhat problematic as we need more people that are good Drupal developers. There is such a strong demand for good Drupal developers, yet which each new version, we add more barriers as a side effect of making Drupal more powerful. As a result, we'll get many more users, but relatively fewer developers. And that's a big problem.
this I agree with.
For most of us eliminating the various SQL schemas makes perfect sense. After all, most of us are expert Drupal developers, and as such, an incremental improvement is easy enough to deal with. However, for new Drupal developers, who are not intimate with Drupal's code, this just increases the barrier.
Why did you end up with Drupal to begin with? Because it had an extremely powerful API for every single problem? Or because it was clean code, easy to get into and make work?
I thought the project lead was cute.
The web is built by millions of individuals, many of which are amateurs. They continuously update, tweak and rebuild their websites. We want Drupal to remain accessible for them.
We do, absolutely. I don't think the proposed extensions are terribly complex ... and they *do* make it easier to read. If i can define my table /once/ and be reasonably assured that that definition is gonna magically work across DB platforms, that sounds much easier to read to me. Furthermore, if there is a bug on one of the platforms, it is more likely due to an incorrect translation in the DB layer, than my just never using system *foo* and not realizing it's SQL syntax variance.
Hence, the challenge is to make Drupal more powerful _AND_ easier to develop for. This requires that we question certain development directions and look at them through the eyes of amateurs.
http://buytaert.net/complexity-is-a-disease http://buytaert.net/why-php-and-not-java
yup, which is why we don't do crap like XML definitions for tables... but something very simple and straightforward - that, however, gains us something very real. my $0.02 (and i haven't read this whole thread yet... so I may well be repeating others). -- James Walker :: http://walkah.net/ :: xmpp:walkah@walkah.net
On 12 May 2006, at 6:00 PM, Dries Buytaert wrote:
Can't we move forward without these functions? It looks like we are introducing more and more dependencies to that makes it harder to move the install system forward. I never said it was a dependency. I said it would make it simpler. We can still do it without this, it's just much more work, the same with every single other schema we are supporting in duplicate or even triplicate.
While an additional database layer (SQL is already an abstraction layer) makes it easier to port Drupal to other database systems, it makes it harder to understand what is going on. It is a lot less accessible to people that are new to Drupal, but that do have a SQL background. So personally, I'm not all that convinced that these functions are a good idea ... This is not about supporting more db types, this is about reducing code, and reducing duplication of it.
I don't think it's sane that every single change to the schema needs to happen in 4 places. I don't like the fact that a contrib module accepting a patch to support postgres, could hold up development of their module. I don't like the fact that postgres and mysql schemas might get out of synch in contrib modules (WITHIN THE SAME _install() FUNCTION). Something like that is incredibly annoying to fix, and increases the amount of code developers need to write, some of which they might not be capable of writing (ie: the postgres schema updates).
I, for one, find it much easier to read an SQL statement than some (new) Drupal-specific table definition. I don't want to learn or use a such definition language. Such functions make the database scheme less transparent. mysqldump -usomething database > database.pgsql or pgsql -Usomething database > database.pgsql
These proposed functions are essentially theme_ functions with a db_query on the result at the end. The 'type' is essentially the index for a map of the types each database uses to represent what we need. The amount of code we stand to remove : (apart from the ~1800 lines of sql we can remove with the extra schemas) And an example of only one of the update_ functions we could have improved. These functions seem to be an average of 20 lines of code, per function, per update that does stuff like this, over ALL OF CORE AND CONTRIB. --- The original (55 lines long) --- function system_update_166() { $ret = array(); $ret[] = update_sql("DROP TABLE {directory}"); switch ($GLOBALS['db_type']) { case 'mysqli': case 'mysql': $ret[] = update_sql("CREATE TABLE {client} ( cid int(10) unsigned NOT NULL auto_increment, link varchar(255) NOT NULL default '', name varchar(128) NOT NULL default '', mail varchar(128) NOT NULL default '', slogan longtext NOT NULL, mission longtext NOT NULL, users int(10) NOT NULL default '0', nodes int(10) NOT NULL default '0', version varchar(35) NOT NULL default'', created int(11) NOT NULL default '0', changed int(11) NOT NULL default '0', PRIMARY KEY (cid) )"); $ret[] = update_sql("CREATE TABLE {client_system} ( cid int(10) NOT NULL default '0', name varchar(255) NOT NULL default '', type varchar(255) NOT NULL default '', PRIMARY KEY (cid,name) )"); break; case 'pgsql': $ret[] = update_sql("CREATE TABLE {client} ( cid SERIAL, link varchar(255) NOT NULL default '', name varchar(128) NOT NULL default '', mail varchar(128) NOT NULL default '', slogan text NOT NULL default '', mission text NOT NULL default '', users integer NOT NULL default '0', nodes integer NOT NULL default '0', version varchar(35) NOT NULL default'', created integer NOT NULL default '0', changed integer NOT NULL default '0', PRIMARY KEY (cid) )"); $ret[] = update_sql("CREATE TABLE {client_system} ( cid integer NOT NULL, name varchar(255) NOT NULL default '', type varchar(255) NOT NULL default '', PRIMARY KEY (cid,name) )"); break; } return $ret; } --- the new version (28 lines) --- function system_update_166() { $ret = array(); db_drop_table("directory"); db_create_table(client, array( 'cid' => array('type' => sequence), 'link' => array('type' => 'short text', 'NOT NULL', 'default' => ''), 'name' => array('type' = 'tiny text', 'NOT NULL', 'default' => ''), 'mail' => array('type' = 'tiny text', 'NOT NULL', 'default' => ''), 'slogan' => array('type' = 'tiny text', 'NOT NULL', 'default' => ''), 'mission' => array('type' = 'tiny text', 'NOT NULL', 'default' => ''), 'users' => array('type' = 'int', 'NOT NULL', 'default' => 0), 'node' => array('type' = 'int', 'NOT NULL', 'default' => 0), 'version' => array('type' = 'tiny text', 'NOT NULL', 'default' => ''), 'created' => array('type' = 'timestamp' , 'NOT NULL' => TRUE, 'default' => 0), 'changed' => array('type' = 'timestamp' , 'NOT NULL' => TRUE, 'default' => 0), )); db_create_table('client_system', array( 'cid' => array('type' => 'int', 'NOT NULL' => TRUE, 'PRIMARY KEY' => TRUE), 'name' => array('type' => 'short text', 'NOT NULL', 'default' => '', , 'PRIMARY KEY' => TRUE), 'type' => array('type' => 'short text', 'NOT NULL', 'default' => ''), )); break; return $ret; } -- Adrian Rossouw Drupal developer and Bryght Guy http://drupal.org | http://bryght.com
"Adrian Rossouw" wrote:
--- The original (55 lines long) ---
--- the new version (28 lines) ---
;) Okay, lines is perhaps not the best quantitative statistic to compare code length. These data give the impression that 'new' is about 1/2 the size of 'old'. But if we consider character count (perhaps a better measure of human effort considering the keystrokes, anyway): new = 1319 old = 1886 Not much of a difference on that level, or not 'as much' of a difference. On the other -- qualitative level -- frankly the 'new' version is much more complicated to read, to my eye. Also, it introduces a greater amount of complexity just to _type_ that 'new' code model. The good thing about the 'old' sample is that the SQL queries represented there are actually transportable -- one can easily copy and paste that DB creation statement, for example, for testing elsewhere, and vice versa. The 'new' form suggestion seems, to me, very much more cumbersome to read, debug and transport. Granted, I am not speaking to any notion of code efficiency regarding run-time execution or even to any notion of what is more "standard" or practical over the long term. -- Gary ...who really would love to see Drupal made easier to use, for the actual end user. PHP programmers love to tweak, change, experiment, and shave micro-seconds off of things, so that's great. But none of that is really making Drupal itself any _easier_ and _more attractive_ to actually use. Lurking and reading the recent discussion has been very useful. There clearly are some very divergent energies about the vision of the future of Drupal, and I am squarely in the "make it easier, improve themes" camp.
I just wanted to put some attention to this old issue. Especially for the install (and update) system, I still think that a transition from direct SQL queries to drupal wrapper functions would be a great advantage, as it would increase database system independence a lot. My patch on http://drupal.org/node/63049 is a working implentation of the proposed functions in mysql. It mainly needs some reviews and discussion. If inclusion into core is being considered, we would of course also need a pqsql version. For some pgsql crack, this should be simple enough to write as he just had to modify the mysql version to fit the postgres sql syntax. regards, Frando
participants (31)
-
Adrian Rossouw -
Angela Byron -
balachandar muruganantham -
Bèr Kessels -
Chris Johnson -
Darrel O'Pry -
Derek Wright -
Dries Buytaert -
Earl Miles -
Fehér János -
Frando -
Frando (Franz Heinzmann) -
Gary (Lists) -
Gerhard Killesreiter -
James Gilliland -
James Walker -
Jeff Eaton -
Jeremy Epstein -
John Pulles -
Karoly Negyesi -
Karthik -
Khalid B -
Larry Garfield -
Mark Janssen -
Michelangelo Partipilo -
moshe weitzman -
Moshe Weitzman -
Richard Morse -
Rowan Kerr -
sime -
Syscrusher