Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Can you show me an example of the 10x less code?



You're going to get a huge reduction in code for all sorts of things, especially when navigating multiple relations, grouping, sub-selects, etc..

  var results = db.myTable
    .where(x => x.value > 6)
    .where(mySpecialConditionalLogicFunction)
    .select(x => { 
      thing = x.relation.relation.relation.value, 
      thingList2 = x.relation.relations
        .groupby(y => y.value)
        .select(g => g.count)
        .orderby(y => y.value)
        .take(5),
      thing3 = x.relations
        .where(z => z.relation1.value < z.relation2.value)
        .select(z => z.relation.value)
        .max(),
      thing4 = myReusableSelectDTOfunction,
      etc..
The sql for this would be very dense, hard to read/maintain. Especially when building structured objects, grouping, filtering etc.. Those composable sub-select functions often build common dtos which ensure the same structured data is sent regardless of the api. And if the dto is updated, all queries inherit it automatically.


This brings fond memories of my early stages where i became fond of the method chaining pattern. I became fascinated by it when using doctrine.

However the code you pasted is horrible and easily replaced by sql. Not only does someone else need to learn your custom logic functions and dtos but they also need to read stuff like “ x.relation.relation.relation.value”. I see your point in regards to dtos “automagically” updating queries, but if you have queries laying around everywhere thats another code smell. Basically, this is solving artificial problems.

The code you pasted can be replaced by a trivial query, which should table columns be renamed (i mean whats the frequency of that anyway, potentially another code smell), it would take less to update than updating all the dtos custom functions and the sausage code.

Edit: i am not belittling you, my point is that the code above solves self inflicted issues that could be written in a basic sql query with bound params. Basically you spend twice as much to write and maintain code that is simply not necessary.


Take a single line from my example 'x.relation.relation.relation.value'

The SQL would be

  select w.value
  from x
  join y on y.relation=x.relation
  join z on z.relation=y.relation
  join w on w.relation=z.relation
1 line for the ORM, 5 lines of SQL. Please give an example where the SQL is less than what I typed in the previous comment.

In addition compiling will validate the ORM code generates valid SQL. On the other hand compiling will not validate a SQL string.

'Custom functions' are just larger versions of the anonymous functions in my example. Very easy for other developers to go to the reference and understand.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: