147

I have a function, parseQuery, that parses a SQL query into an abstract representation of that query.

I'm about to write a function that takes an abstract representation of a query and returns a SQL query string.

What should I call the second function?

Simon
  • 24,010
  • 36
  • 139
  • 249
  • Stringify? JSON class uses this terminology. [JSON.parse](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse) and for the opposite [JSON.stringify](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)? – Wilt May 31 '16 at 10:28

33 Answers33

200

I think the verb you want is 'compose'.

Joel Coehoorn
  • 362,140
  • 107
  • 528
  • 764
78

The opposite of parse is serialize

Yuval Adam
  • 149,388
  • 85
  • 287
  • 384
32

In compiler terminology, the opposite is "unparse". Specifically, parsing turns a stream of tokens into abstract syntax trees, while unparsing turns abstract syntax trees into a stream of tokens.

Barry Kelly
  • 39,856
  • 4
  • 99
  • 180
31

Compose? When parsing a query you break it into its constituent parts (tokens, etc.), the reverse would be composing the parts into a string query.

Michael Brown
  • 8,677
  • 1
  • 25
  • 37
21

To complement your existing naming, composeQuery looks best.

But in the general case, the opposite of parse is ǝsɹɐd

danja
  • 1,030
  • 2
  • 10
  • 14
20

I would use one of these:

  • ToString()
  • ToSQL()
  • Render()
Sklivvz
  • 28,698
  • 24
  • 111
  • 164
17

I think "serialize" is probably the word you want. It means to produce a textual representation of data that can be exported (and imported) from the program.

Kyle Cronin
  • 72,761
  • 40
  • 144
  • 160
  • 1
    Serialize can just as easily mean a binary representation. – Ben Hoffstein Sep 29 '08 at 14:27
  • 1
    True. Parsimg is all about fading in external data, and serialization is all about producing data for external uses. The format produced isn't required to be text, but often is. – Kyle Cronin Sep 29 '08 at 14:34
  • Apparently my iPod's keyboard is getting the better of me. That's supposed to be "parsing" and "reading". – Kyle Cronin Sep 29 '08 at 14:37
15

The antonym of 'analyze' is 'synthesize'.

13

ToQueryString()

plinth
  • 45,549
  • 9
  • 75
  • 118
12

Definitely Render.

Amanda Mitchell
  • 2,537
  • 1
  • 15
  • 23
10

I would call it constructQuery.

Sec
  • 6,546
  • 5
  • 29
  • 57
  • That sounds almost perfect. That is what would be happening. He would be collecting data that could be "put into words". He would "construct" a query. – Tgwizman Apr 28 '16 at 14:42
10

generate or emit, possibly.

DGentry
  • 15,552
  • 7
  • 48
  • 65
10

Just to add some stuff.

Surely parse is a two way word.

You can parse an abstract into a query.

You can parse a query into an abstract.

The question should be, what do you name the latter part of the method, and because in this instance you're parsing an abstract to make a query you'd call it parseAbstract.

To answer the question, parsing has no opposite.

Henry B
  • 7,574
  • 9
  • 40
  • 45
9

generateQuery, possibly? createQuery?

Dre
  • 4,121
  • 27
  • 39
8

Take your pick

  • Generate
  • Dump
  • Serialize
  • Emit

They each have slightly different connotations.

Mike Graham
  • 64,557
  • 13
  • 91
  • 125
7

Maybe prettyPrintQuery?

fhe
  • 5,847
  • 1
  • 37
  • 40
7

compose, construct, generate, render,condense, reduce, toSQL, toString depending on the nature of the class and its related operators

MikeJ
  • 14,193
  • 20
  • 67
  • 85
6

A traditional compiler has two parts: a parser and a code generator.

So you could call it "Generate". Of course, it's a little bit different here because the compiler isn't writing source code. (unless it's a precompiler).

Walter Mitty
  • 16,496
  • 2
  • 24
  • 53
5

Possibly Format(). or ToSQL() in your instance?

Omar Kooheji
  • 50,943
  • 65
  • 176
  • 234
5

unParse()? Just kidding, I would go with toQueryString()

Ben Hoffstein
  • 98,117
  • 8
  • 99
  • 119
4

flatten?

The parsed query object perhaps represents a condition hierarchy, which you are "flattening" back into a 1 dimensional string.

But given that you're going from object to string, really just use toString or toSQL() or something like that. Besides, if you designed it well and are using the right app, you can rename it later and just stick stuff in the comments on what it does.

Josh
  • 16,016
  • 6
  • 43
  • 62
4

I'd say serialize and deserialize, instead of parse and ...

Christophe Herreman
  • 15,366
  • 7
  • 55
  • 86
4

I would go for ToString(), since you can usually chain-nest them (opposite functions, that let you pass from Class1 to Class2 and vice-versa)

DateTime.Parse( DateTime.Parse( myDate.ToString() ).ToString() );

Serialize() looks like a nice choice, but it already has an opposite in Deserialize().

In your specific scenario, as other pointed out, ToSql() is another good choice.

Filini
  • 2,041
  • 2
  • 22
  • 32
4

I'd use render

> a = 'html': { 'head': {'title': 'My Page'}, 'body': { 'h1': 'Hello World', 'p': 'This is a Paragraph' } }

> b = render(a)

> console.log(b)

<html>
    <head>
        <title>My Page</title>
    </head>
    <body>
        <h1>Hello World</h1>
        <p>This is a Paragraph</p>
    </body>
</html>

Which is IMHO, the opposite to parse()

> c = parse(b)

{ 'html': {
    'head': {
        'title': 'My Page'
    }
    'body': {
        'h1': 'Hello World',
        'p': 'This is a Paragraph'
    }
}
Herman Junge
  • 2,709
  • 22
  • 19
3

INHO Serialize, synthesize are good options. Also, as you have named parseQuery, i will go with codeQuery

mbmihura
  • 512
  • 1
  • 8
  • 13
3

+1 for Generate, but tack on what you're generating, i.e. GenerateSQL()

Tom Lahti
  • 71
  • 1
3

I voted for 'compose' but if you don't like that I would also suggest 'build'

Guy
  • 59,547
  • 93
  • 241
  • 306
3

I usually use "parse" as a conversion method and, therefore, i can't find a opposite word for "convert". (you can't "deconvert" something, as "unconvert" is a type of conversion itself).

thinking this way, the best solution (for me) is having two "parse" methods that receive different arguments. Example (Java):

public class FooBarParser{

    public Foo parse(Bar bar);
    public Bar parse(Foo foo); 
}
David Paulo
  • 413
  • 3
  • 10
3

What about asSQL() or even more asQuery()?

Müge
  • 71
  • 3
2

deparse

Deparse is to parse, as:

  • decompile is to compile
  • decompose is to compose
  • deserialize is to serialize
  • degroovy is to groovy :) ;)

Parsing / deparsing is not change of structure, but conversion. Precise conversion between equivalent text and abstract-syntax-tree formats, maintaining all relationships & structure.

"Compose" means change of structure, so is not quite right. It suggests combining from separate independent parts (usually for the first time). Just as "decompose" suggests splitting into independent parts. They change form, not just format.

A quick search show's the term's used within:

Glen Best
  • 21,413
  • 2
  • 52
  • 72
  • A quick Github Code search reveals that the term "deparse" has no widespread usage, see https://github.com/search?q=deparse - I think of "deparse" as a term from the R ecosystem. - For me the opposite of parsing is generating. In **parsing**, we have a sentence and a grammar as input and want to know what the syntactic structure and/or the semantics representation of the sentence is. In **generation**, we have a semantic representation and a grammar as input and want to find sentences that correspond to the semantic representation. – Jens A. Koch Aug 27 '15 at 13:20
0

writeQuery. Parse is the act of reading it from a string and creating the object (let's say 'actual') representation. The opposite would be writing the object into a string.

helios
  • 12,916
  • 2
  • 41
  • 51
0

.GetSqlQuery() would be my choice

Xaqron
  • 26,135
  • 39
  • 130
  • 194
-6

I believe the answer you're looking for is: "Don't parse SQL or assemble SQL in the first place. Use an Object/Relational Mapper and stop wasting your employer's money by solving problems that have already been solved for quite some time."

chadmyers
  • 3,770
  • 19
  • 29
  • -1. You have no idea what he's doing. He might have a perfectly good reason for doing it. Not all applications are the same. – erikkallen Oct 20 '09 at 21:03
  • 1
    I must agree, I had recently a perfectly good reason to parse SQL that had nothing to do with ORM's (which I used in the project as well). – Craig Oct 20 '09 at 21:46
  • I'd love to hear this 'perfectly good reason'. No, actually I wouldn't. I could imagine if you were building a SQL IDE or something, but even then -- why are you building a SQL IDE when they are some heavy hitters in the market already? – chadmyers Oct 20 '09 at 22:05
  • 1
    Reason was basically we had to turn a query 'SELECT CustomerId FROM Customer' into something like 'SELECT <> FROM <>'. This is easy for basic select, very difficult for complex queries. – Craig Oct 20 '09 at 22:35
  • 3
    Please tell me how nHibernate would help me to do this? – Craig Oct 20 '09 at 22:35
  • Please tell me why you'd be doing that in the first place. – chadmyers Nov 06 '09 at 17:36