Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Brecht posted:

SQL is already a DSL for (deep breath here) structured queries, if at the end of the day you're operating on structured data you're necessarily writing structured queries and you might as well do it with the tool that's been expressly designed for that purpose. You don't need another layer of abstraction for what is already a purpose-built layer of abstraction, the only possible consequence of that is you take a net loss. Not having to write SELECT FROM WHERE is a false economy when you just hide it behind the context-destroying façade of an ORM.

The problem isn't SELECT FROM WHERE, it's "SELECT FROM WHERE." If you're using a language worth using in 2011 or C#, it's powerful enough to represent the same concepts as SQL without having to put quotation marks around it or jam yet another language into your app.

I don't usually write my own ASM and I don't usually write my own SQL.

Adbot
ADBOT LOVES YOU

A A 2 3 5 8 K
Nov 24, 2003
Illiteracy... what does that word even mean?

Brecht posted:

tl;dr SQL isn't hard, use it

SQL and database design must be harder for newer developers than the object-oriented languages they're used to. I don't have a better way to make sense of recent attitudes about relational databases.

Combine that with attitudes from early in a development career like abstraction is good for its own sake, and everything has to be an object, and you inevitably get overuse of ORMs.

Combine it with naive ideas about performance and scale and desire for silver bullets and you get overuse of schemaless data stores.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

A A 2 3 5 8 K posted:

SQL and database design must be harder for newer developers than the object-oriented languages they're used to. I don't have a better way to make sense of recent attitudes about relational databases.

Maybe it's the sudden realization that there are choices other than relational database or a bunch of files.

hepatizon
Oct 27, 2010

Brecht posted:

context-destroying façade of an ORM.

:madmax:

I think people are kind of overlooking the O part of ORM. They don't just construct a SELECT, they handle the boring process of converting results into useful objects, which is cool if you're not just dumping results to a page.

Also, no ORM aims to totally abstract a complex subquery. The point of wrapping a SELECT is that the majority of queries in the majority of applications are brainless boilerplate and the programmer shouldn't even have to think about how they're constructed, any more than they should have write i = 0; i++ in a foreach.

Frozen Peach
Aug 25, 2004

garbage man from a garbage can

tef posted:

Hell is other peoples code. We are all the horror.

:monocle:

There are only 2 real reasons to use an ORM.

1) To have further protection against SQL injection

This can be mitigated with good code and sanitizing user input. The ORM just lets a coder be lazy and not give a poo poo, which is a good thing. Even WITH an ORM you should still write good code and sanitize user input.

2) Allows you to easily move from one database language to another.

If you're never going to change your database language, you don't need to worry about this either.

As for a REAL horror, this is a cross post from the SQL thread:

Without going into too much detail, we have a database that stores a MARC record bibliography tag, and it's raw subfields. Basically data in a field that looks like this, but the [1F] is an invisible hex character you can't see unless you know it's there:

[1F]aTitle of a book /[1F]b Subtitle[1F]cby Author Name

I needed a way to select data within one subfield. This ended up being the solution thanks to having no better way of doing it in the abomination that is MS SQL 2000.

code:
SELECT taginfo 
FROM   marctags mt 
WHERE  tagnumber = '245' 
       AND Substring(mt.taginfo, Charindex('[1F]a', mt.taginfo) + 2, 
               Charindex('[1F]', Substring(mt.taginfo, 
                                 Charindex('[1F]a', mt.taginfo) + 
                                 2, 
                                 Len( 
                                 CAST( 
                             mt.taginfo AS VARCHAR 
                             (3000))) - Charindex('[1F]a', mt.taginfo) + 2) + 
                                 '[1F]') 
               - 1) LIKE '%Harry%' 

tef
May 30, 2004

-> some l-system crap ->
should we start a orm/sql apologist thread? it's like tabs vs spaces in here

Zombywuf
Mar 29, 2008

tef posted:

it's like tabs vs spaces in here

Tabs vs. spaces are handled for you in a decent text editor like Emacs.

hepatizon
Oct 27, 2010

tef posted:

should we start a orm/sql apologist thread? it's like tabs vs spaces in here

More like HLL vs assembly.

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
Tabs save filesize and discourage devs from formatting their code in clever (terrible) ways. Four-width tabs are of course the best.

HLL are the only real choice with the exception of areas where speed is of critical importance, like a realtime system, or things like video encoding and resource-intensive games. Everything else should be written in a HLL and use its standard library, and other libraries, before trying to recreate the wheel.

tef
May 30, 2004

-> some l-system crap ->

hepatizon posted:

More like HLL vs assembly.

:allears: this is the thread that keeps giving.

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

It's a shame RSF doesn't happen anymore, we could have had one that had a thread for each classic IT flamewar to keep them clear of all the other forums. Though I suppose that's what YOSPOS was meant to be...

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

Frozen-Solid posted:

sanitizing user input ... sanitize user input.

Nooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Get this guys: sometimes I use an ORM and sometimes I use SQL.

I'm loving crazy.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Otto Skorzeny posted:

Nooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

Hmm, sanitizing user input. That just means that you check that $('#thefield').val().indexOf('`') == -1 before submitting the form, right?

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

Thermopyle posted:

Get this guys: sometimes I use an ORM and sometimes I use SQL.

I'm loving crazy.

You're literally a Class traitor.

blorpy
Jan 5, 2005

Ok, if you haven't figured it out yet, it's time for me to admit I was just kidding. I thought the gig was up when shrughes called me out, but no...

blorpy
Jan 5, 2005

Markov Chain Chomp posted:

Ok, if you haven't figured it out yet, it's time for me to admit I was just kidding. I thought the gig was up when shrughes called me out, but no...

Ahaha, yeah right, you just flipped positions and now you're back pedaling. You probably really didn't understand SQL. Now you better start worshipping a shrine of Victor.

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"
code:
let genBind decl = do
        varName <- newName "opt"
        exp <- case decl of 
                GroupDecl{} -> return (BindS (VarP varName) var_groupParse)
                OptionDecl' (OptionDecl fname shorts longs def _ qParserExp _ _) -> do
                        valExp <- case lookup fname valDecls of
                                Just e -> e
                                Nothing -> [| (\_ -> valid) |]
                        parserExp <- qParserExp
                        return (BindS
                                (VarP varName)
                                (AppE   
                                        (AppE   
                                                (AppE   
                                                        (AppE   
                                                                (AppE   
                                                                        var_optionParse
                                                                        (LitE (StringL shorts)))
                                                                (ListE (map (LitE . StringL) longs)))
                                                        (LitE (StringL def)))
                                                parserExp)
                                        valExp))
                _ -> return (LetS [])
        return (varName, exp)

Look Around You
Jan 19, 2009

Janin posted:

code:
let genBind decl = do
        varName <- newName "opt"
        exp <- case decl of 
                GroupDecl{} -> return (BindS (VarP varName) var_groupParse)
                OptionDecl' (OptionDecl fname shorts longs def _ qParserExp _ _) -> do
                        valExp <- case lookup fname valDecls of
                                Just e -> e
                                Nothing -> [| (\_ -> valid) |]
                        parserExp <- qParserExp
                        return (BindS
                                (VarP varName)
                                (AppE   
                                        (AppE   
                                                (AppE   
                                                        (AppE   
                                                                (AppE   
                                                                        var_optionParse
                                                                        (LitE (StringL shorts)))
                                                                (ListE (map (LitE . StringL) longs)))
                                                        (LitE (StringL def)))
                                                parserExp)
                                        valExp))
                _ -> return (LetS [])
        return (varName, exp)

Holy poo poo.

Deus Rex
Mar 5, 2005

edit: never mind

Deus Rex fucked around with this message at 07:18 on Dec 12, 2011

Opinion Haver
Apr 9, 2007

What's that from? It's pretty obviously Haskell, I'm guessing it's some kind of funky metaprogramming stuff?

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

yaoi prophet posted:

What's that from? It's pretty obviously Haskell, I'm guessing it's some kind of funky metaprogramming stuff?

Looks like part of some Template Haskell for some option-parsing library; that's producing a Haskell expression at compile-time by direct manipulation of syntax trees to serve some purpose. Template Haskell is pretty ugly to begin with, and the indentation is not helping at all, there.

Beef
Jul 26, 2004

quote:

Any decent ORM would ...

is the new "sufficiently smart compiler".

Comrade Gritty
Sep 19, 2011

This Machine Kills Fascists

Frozen-Solid posted:

:monocle:

There are only 2 real reasons to use an ORM.

1) To have further protection against SQL injection

This can be mitigated with good code and sanitizing user input. The ORM just lets a coder be lazy and not give a poo poo, which is a good thing. Even WITH an ORM you should still write good code and sanitize user input.

2) Allows you to easily move from one database language to another.

If you're never going to change your database language, you don't need to worry about this either.


Emphasis mine.

If you're attempting to sanitize input instead of using a prepared statement you are exactly the sort of person who should never be writing SQL manually.

SQL is a lovely DSL that requires me to leave the language I prefer to write in, to write in another language. I use an ORM because I like writing in my preferred language and I like operating on objects.

That being said anyone who thinks "Use the ORM Luke" is the only answer and you never need raw SQL (or that an ORM is always the answer at all) is an idiot. Any ORM worth using has a way of dropping to raw SQL and optionally populating the object(s) from that raw SQL. Because, surprise!, sometimes the ORM writes brain dead SQL and you need to write it your self if you don't want to bog your app down.

Frozen Peach
Aug 25, 2004

garbage man from a garbage can

Steampunk Hitler posted:

Emphasis mine.

If you're attempting to sanitize input instead of using a prepared statement you are exactly the sort of person who should never be writing SQL manually.

There's more to sanitizing user input than just escaping quotes to prevent injection. Every piece of user input should be checked for validity long before it even sees SQL. The fact that people think SQL injection is the only reason for sanitizing user input is the horror here.

Comrade Gritty
Sep 19, 2011

This Machine Kills Fascists

Frozen-Solid posted:

There's more to sanitizing user input than just escaping quotes to prevent injection. Every piece of user input should be checked for validity long before it even sees SQL. The fact that people think SQL injection is the only reason for sanitizing user input is the horror here.

Now you're backpedaling, you explicitly said that you should sanitize input to prevent SQL Injections. There are other, valid, reasons to sanitize input but your statement didn't mention them, it only claimed that the "correct" way to handle App -> DB code was to sanitize input which it patently wrong.

Frozen Peach
Aug 25, 2004

garbage man from a garbage can

Steampunk Hitler posted:

Now you're backpedaling, you explicitly said that you should sanitize input to prevent SQL Injections. There are other, valid, reasons to sanitize input but your statement didn't mention them, it only claimed that the "correct" way to handle App -> DB code was to sanitize input which it patently wrong.

No, I said there are only 2 real reasons to use an ORM, and specifically stated that you should be sanitizing user input anyways. Yes, it was in relation to a comment about preventing injection, but the intent was that sanitizing is something you should be doing beyond just SQL injection and that user input should be validated and sanitized even if it's not going to be put anywhere near a database. Thus, an ORM to prevent injection is just another safety net.

Brecht
Nov 7, 2009

Steampunk Hitler posted:

SQL is a lovely DSL that requires me to leave the language I prefer to write in, to write in another language. I use an ORM because I like writing in my preferred language and I like operating on objects.
What a strange series of assertions. SQL is an excellent DSL for writing structured queries. Your preferred language for operating on objects is excellent for operating on objects. These are totally separate domains. The coding horror is shoehorning one into the other because it's what you prefer to do, rather than choosing the correct tool to solve the problem you're faced with.

quote:

Any ORM worth using has a way of dropping to raw SQL and optionally populating the object(s) from that raw SQL. Because, surprise!, sometimes the ORM writes brain dead SQL and you need to write it your self if you don't want to bog your app down.
The fundamental assumption underlying this statement is that the raison d'etre of structured queries is to "populate [an] object," which is a weird and super narrow way of perceiving RDBMSs and SQL.

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

yaoi prophet posted:

What's that from? It's pretty obviously Haskell, I'm guessing it's some kind of funky metaprogramming stuff?

ShoulderDaemon posted:

Looks like part of some Template Haskell for some option-parsing library; that's producing a Haskell expression at compile-time by direct manipulation of syntax trees to serve some purpose. Template Haskell is pretty ugly to begin with, and the indentation is not helping at all, there.
yup

It's part of an option parsing library I'm writing, which lets users define options using templates.

the end result is pretty and nice to use, but the innards :gonk: . This is my first time ever using template haskell, and I feel like some CS101 freshman confronted with a switch statement.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Steampunk Hitler posted:

SQL is a lovely DSL that requires me to leave the language I prefer to write in, to write in another language.

Your complaint is that a different language requires you to use... a different language?

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Janin posted:

yup

It's part of an option parsing library I'm writing, which lets users define options using templates.

the end result is pretty and nice to use, but the innards :gonk: . This is my first time ever using template haskell, and I feel like some CS101 freshman confronted with a switch statement.

Use AppE in `infix` position if you have to use it at all and it tends to get a bit more readable. If you're doing this a lot, just make an operator for it.

You don't usually need to do things like ListE (map (LitE . StringL) longs) when you can just [|longs|]. I try to avoid LitE altogether. In general, TH looks a lot nicer if you use the quoters to do as much heavy lifting as possible. Remember that you can use Template Haskell in your Template Haskell.

code:
  let qValExp = fromMaybe [| const valid |] $ lookup fname valDecls
  bindExp <- [| $(return var_optionParse) shorts longs def $(qParserExp) $(qValExp) |]
  return $ BindS (VarP varName) bindExp

shrughes
Oct 11, 2008

(call/cc call/cc)
In Coffeescript:

z = [0..2] becomes z = [0, 1, 2]

z = [0..1] becomes z = [0, 1]

z = [0..0] becomes z = [0]

z = [0..-1] becomes z = [0, -1]

Then there's z = [0...n], the secret feature which does what you want and isn't documented.

Opinion Haver
Apr 9, 2007

shrughes posted:

In Coffeescript:

z = [0..2] becomes z = [0, 1, 2]

z = [0..1] becomes z = [0, 1]

z = [0..0] becomes z = [0]

z = [0..-1] becomes z = [0, -1]

Then there's z = [0...n], the secret feature which does what you want and isn't documented.


Nope:

quote:

Ranges can also be used to extract slices of arrays. With two dots (3..6), the range is inclusive (3, 4, 5, 6); with three dots (3...6), the range excludes the end (3, 4, 5).

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

ShoulderDaemon posted:

Remember that you can use Template Haskell in your Template Haskell.
:aaaaa:

gonna clean all that up after work, thanks much

w00tz0r
Aug 10, 2006

I'm just so god damn happy.
"So hey, boss, since we're looking for a new guy, are we looking for a new grad, or someone more senior?"
"New grad, if we hire someone with experience we'll have to make them unlearn all of their bad habits."

The irony is blowing my loving mind.

Sedro
Dec 31, 2008
If only there was some process to weed out bad applicants.

Zhentar
Sep 28, 2003

Brilliant Master Genius
Looking at w00tz0r's post history in this thread, I don't think he was bothered by the concept (which is pretty legit) so much as the idea that there might be a risk of hiring people who actually manage to have worse habits than those the team already has in place.

w00tz0r
Aug 10, 2006

I'm just so god damn happy.

Zhentar posted:

Looking at w00tz0r's post history in this thread, I don't think he was bothered by the concept (which is pretty legit) so much as the idea that there might be a risk of hiring people who actually manage to have worse habits than those the team already has in place.

bingo.

shrughes
Oct 11, 2008

(call/cc call/cc)

yaoi prophet posted:

Nope:

Nsry, that's the section on array slicing and not on ranges.

Adbot
ADBOT LOVES YOU

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
What section on ranges?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply