r/webdev • • May 18 '25

Discussion I wonder why some devs hate server side javascript

I personally love it. Using javascript on both the server and client sides is a great opportunity IMO. From what I’ve seen, express or fastify is enough for many projects. But some developers call server side javascript a "tragedy." Why is that?

193 Upvotes

254 comments sorted by

View all comments

Show parent comment

1

u/c-digs May 21 '25

What's the price? Price implies I've given something up in exchange. Is it slower? Lower throughput? Would love to know what the price is here.

In fact, it is in JS where the price is paid in lower throughput and peformance by requiring Zod or another runtime schema validator to replace the loss of runtime types.

1

u/efari_ May 21 '25

the price is you defining the type and the scheme...

1

u/c-digs May 21 '25 edited May 21 '25

I did not define a schema; I merely defined a type. In a typed runtime, the build process does not wipe out the type metadata and retains it so it can be introspected.

Let's look at this in TS:

type Person = {
  firstName: string
  age: number
}

const PersonSchema = z.object({
  firstName: z.string(),
  age: z.number()
})

Or alternatively, I give up my type:

const PersonSchema = z.object({
  firstName: z.string(),
  age: z.number()
})

type Person = z.infer<type PersonSchema>

// And now I am working with Zod, not types because my types
// are inferred from Zod; the type-schema relationship is 
// inverted.

Or I have to use class-validator like approach:

class Person {
  @IsString() // 👈 The runtime JS needs this to know this is a string
  firstName: string; // 👈 TypeScript knows this is a string

  @IsNumber() // 👈 The runtime JS needs this to know this is a number
  age: number; // 👈 TypeScript knows this is a number
}

In fact, it is here that I've done extra work, is it not?

I iterate again, this is what I do in C#:

record Person(
  string FirstName, 
  int Age
);

And I'm done because my type metadata does not get wiped out at build time