Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am designing a new programming language.

I am designing a syntax to implement queries. Currently this is how it works.

The database is accessible through entity object.

on this sample I have "entity.manufacturers" and "entity.products" table

To get manufacturer with an ID of 1:

   var @manufacturer = entity.manufacturers where id = 1;

To query all products for @manufacturer:

    // Get all manufacturers products 
    var @products = entity.products under @manufacturer;
    // No need to specify what links both since system already knows how entity is related

Currently I am using "under" as a keyword to get all records for @manufacturer. I want it to make sense by just reading the code.

If you can give suggestions on a better syntax or keywords on how to implement this that will be awesome.

share|improve this question

closed as not constructive by Jim G., Martijn Pieters, Dynamic, MichaelT, Karl Bielefeldt Mar 20 '13 at 20:59

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

Why not just implement SQL as a native query language? – Michael Brown Mar 20 '13 at 17:52
For simplicity. Its too complicated to implement the whole SQL syntax. – Richard Heath Mar 20 '13 at 17:56
Well, you are basically describing Linq. – Robert Harvey Mar 20 '13 at 18:04
Do you have to do the "whole" SQL Syntax? I like the use of 'under' but only as a substitue for UNION. – JeffO Mar 20 '13 at 18:11
have you considered something like the grep { code block } @collection syntax of perl? – user40980 Mar 20 '13 at 18:15
up vote 1 down vote accepted

Designing good concrete syntax is ridiculously hard. And unfortunately, while the best syntax in the world can't save a lame language, bad syntax can (has) doom(ed) good languages.

If this is a toy language, "full speed ahead" say I! But if you want to create a practical language for people to use, I have the following observations based on my personal experiences. YMMV:

  • focus on the semantics and abstract syntax of your language. This is the core of a language, and how people will learn and understand it. Figure out how elements of the language can be defined, combined, and abstracted. Absolutely do not let concrete syntax dictate the semantics or abstract syntax of your language.
  • keywords, braces, semicolons -- these are all totally irrelevant as far as abstract syntax and semantics are concerned. There can be multiple concrete syntaxes for the exact same language.
  • implementing features as libraries is usually preferable to implementing them as syntax
  • syntax is hard to fix
  • syntax is hard to extend
  • syntax is hard to compose
  • syntax is not accessible at run-time

So my answer to your question is: design your abstract syntax and semantics first. Without seeing those, it's very hard to come up with a good concrete syntax. Once you have those, a concrete syntax should be much easier to derive.

Or you could just go with Lisp. ;)

Also, since you mentioned I want it to make sense by just reading the code, I should point out that designing a syntax that reads like plain English, yet is also simple, unambiguous and powerful has never been done (to my knowledge). I do not believe this is possible (although I hope I am wrong).

share|improve this answer
Thank you for the tip. This will surely help me in designing the language. – Richard Heath Mar 20 '13 at 21:11
@RichardHeath good luck! Try lots of stuff. Make mistakes. Build something awesome! – user39685 Mar 20 '13 at 23:52

I don't think under is the right word here as it makes to many assumptions about the nature of the relationship between two entities, when all you really need to indicate is fact that they are related. In many entity relationship, one entity may be thought of as under another, but this is certainly not the case for all entity relationships.

I'd use the word by instead, as in

var @products = entity.products by @manufacturer;

Or on, as in

var @products = entity.products on @manufacturer;

Since it hints that you are creating a simplified join syntax.

share|improve this answer
You are right. I think "on" will be a better keyword. It does make more sense than under when used on entity with multiple relationship. – Richard Heath Mar 20 '13 at 18:54

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