by losvedir · 10y ago · 0 comments
* Graphical programming environment (they run the queries
from pgadmin, or Postico, or some app like that)
* Instant feedback - run the query get useful results
* Compilation step with some type safety - will complain
if their query is malformed
* Are tables a "natural" way to think about data for humans?
* Job relevance
Any ideas? Can we learn from that example to make real programming environments that are more "cross functional" in that more people in a company are willing to use them? for user in table_users:
if user.is_active:
return user.first_name;
vs: SELECT first_name FROM users_table
WHERE is_active
It's unfortunate that the order of the clauses in SQL is "wrong" (e.g. you should say FROM, WHERE, SELECT: Define the universe of relevant data, filter it down, select what you care about), but it's still quite easy to wrap your mind around. You are asking the computer for something, and if you ask nicely, it tells you what you want to know. Compare that to procedural programming, where you are telling the computer what to do, and even if it does what you say, that may not have been what you actually wanted after all.SQL is written goal-oriented.
You start with what you want (the goal). Then you specify from where (which can also be read as "what", since each table generally describes a thing) and finally you constrain it to the specific instances you care about.
SELECT the information I want FROM the thing that I care about WHERE condition constrains results to the few I want
Having said that, I would personally still prefer it in reverse like you say. I can see the value of how SQL does it, though, especially for non-programmers who think less about the process of getting the results and more about the results they want (because they haven't been trained to think of the process, like programmers have).
It makes sense for someone who isn't thaaaaat technical to start with "well, I want the name and salary of the employee but only those that are managers": SELECT name, salary FROM employee WHERE position = 'manager'
Admittedly even that isn't perfect and I assume that it wouldn't take much for someone to learn the reverse.
A feature like this may help your programmers who are used to thinking in terms of filter -> select -> order.
Procedural vs. functional phrasing in no way changes the basic fact that if you ask a computer the wrong question it'll give you the wrong result.
"go through the list of all users and add the ones which are active to a new list"
vs.
"the list I want contains all active users from the list of all users"
As long as the instructions are longer than the question (and they often are, even in your example ;)), you are bound to make more errors here.
Plus, it requires some understanding of how this damn machine works in the first place.
When turning questions into instruction is decidable it pays off to automate it.
[user.first_name for user in table_users if user.is_active]For instance, the SQL query can be parallelized, but not so with the Python list comprehension. If you wanted to create a version that could be run in parallel in Python, you'd have to do it with a map()/filter() construct. Ignoring readability for a sec (pretend it's nice and elegant, like it would be in e.g. Clojure), you are still specifying how the machine should accomplish the goal, not the goal itself.
filter(lambda x: x is not None, map(lambda u: u.first_name if u.is_active else None, table_users))http://2015.padjo.org/tutorials/sql-walks/exploring-wsj-medi...
My main reason for teaching it was that it was a skill that helped me immensely as a journalist, in terms of being able to do data analysis. Because I learned it relatively late in my career, I thought it'd be hard for the students but most of them are able to get it.
Even though I use relatively little SQL in my day to day work, it's my favorite thing to teach to novices. First, it has a similar data model to spreadsheets, so it feels like a natural progression. Secondly, for many students, this is the first time that they'll have done "real" programming and the first time that they learn how to tell a computer to do something rather than learn how to use a computer. In Excel, for example, you double click a file and the entire thing opens. With SQL, you're required to not just specify the database and table, but also each and every column...it's annoying at first, but then you realize that there is power in being explicit.
The main advantage of teaching SQL over, say R, as a first language is that SQL's declarative syntax is easy to follow AND you can do most of what you need with a limited subset of the language...for instance, I don't have to teach variables and loops and functions...which is good because I don't even know how to really do those in SQL (just haven't had the need when I can work from R or Pandas).
When a beginner student fucks up a basic Python script, there are any number of reasons for the failure that is beyond the student's expected knowledge. When a novice student fucks up a SQL query...it's easier to blame the mistake on the student (e.g. Misspelling of names/syntax)
We provide low code platform (SQL) to organize data and build custom applications as per specific workflow requirements. We are assuming that teaching/educating/training combined with lots of sample SQL code with real world examples are helpful to non-programmers for using SQL.
Sample SQL is available at https://mydataorganizer.com/MyDataOrganizer/QuarterDatesCalc...
Thanks, Neal
Thats barely programming. Even by the most lenient definition what they do isn't programming.
Firstly SQL's are a little like Excel Macros, they lower the barrier to entry to basic twiddling. Got a SQL client(Toad etc?)? you can throw a snippet or two quickly. Anything beyond that gets difficult. Tricky joins, sub queries, troubleshooting big queries, optimization problems etc etc. Beyond this writing re usable code, test discipline and a range of other tasks that make code run for years is what is your everyday work as a programmer.
Sure you could saw a log of wood once a while, but don't confuse that for being a full time carpenter.