147
votes

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?

1

33 Answers 33

200
votes

I think the verb you want is 'compose'.

6
  • 3
    @Joel : twitter.com/shanselman/status/5024768993 Oct 20, 2009 at 19:34
  • 16
    I mean, coming back a year later I'd even answer 'assemble' as a better opposite, or 'build' as a better function name. Oct 20, 2009 at 19:35
  • 3
    Oh wow, I didn't check the dates on this... SO question necromancy! Oct 20, 2009 at 19:37
  • err.. why not ToString() ? Seems to be the standard set by the likes of Int32, etc Oct 20, 2009 at 20:06
  • 1
    made my previous comment before seeing that the question was language-agnostic. ToString() seems to be the accepted standard by .NET Oct 20, 2009 at 20:08
78
votes

The opposite of parse is serialize

2
  • 1
    This may be the most useful answer from my perspective. Dec 17, 2014 at 17:25
  • 8
    What about 'deserialize'?
    – Den
    Apr 27, 2015 at 21:38
32
votes

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.

1
  • 4
    Like to uncrash a car ... Sep 10, 2015 at 20:15
31
votes

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.

21
votes

To complement your existing naming, composeQuery looks best.

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

2
  • 8
    I think that's the inverse, the opposite would be esrap Dec 17, 2014 at 16:12
  • @agusgambina: actually, this makes sense... Think about Bourne shell : if...fi case...esac
    – shrike
    Jun 18, 2016 at 7:26
20
votes

I would use one of these:

  • ToString()
  • ToSQL()
  • Render()
0
17
votes

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.

3
  • 1
    Serialize can just as easily mean a binary representation. Sep 29, 2008 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. Sep 29, 2008 at 14:34
  • Apparently my iPod's keyboard is getting the better of me. That's supposed to be "parsing" and "reading". Sep 29, 2008 at 14:37
15
votes

The antonym of 'analyze' is 'synthesize'.

1
  • 4
    synthesize. good choice.
    – MikeJ
    Sep 29, 2008 at 16:21
13
votes

ToQueryString()

12
votes

Definitely Render.

10
votes

I would call it constructQuery.

1
  • 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, 2016 at 14:42
10
votes

generate or emit, possibly.

1
  • 1
    I agree. rfc7159 (JSON), in sections 9 and 10 define "Parser" and "Generator" as opposites. Feb 26, 2015 at 6:14
10
votes

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.

9
votes

generateQuery, possibly? createQuery?

0
8
votes

Take your pick

  • Generate
  • Dump
  • Serialize
  • Emit

They each have slightly different connotations.

7
votes

Maybe prettyPrintQuery?

7
votes

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

6
votes

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).

5
votes

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

5
votes

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

0
4
votes

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.

4
votes

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

4
votes

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.

4
votes

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'
    }
}
3
votes

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

3
votes

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

3
votes

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

3
votes

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

3
votes

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); 
}
2
votes

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:

1
  • A quick Github Code search reveals that the term "deparse" has no widespread usage, see 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. Aug 27, 2015 at 13:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.