logoalt Hacker News

jsontwikkelingtoday at 1:47 PM1 replyview on HN

Great to hear that. I actually think TypeScript is very fit for the purpose, even better than Python (lacks types) or Java (bulkier).

Type signatures document contracts directly:

  export function rabinKarp(text: string, pattern: string): number[]
Clear that it takes two strings and returns match positions. No separate explanation needed.

Interfaces model return types and ADTs cleanly:

  export interface ShortestPathResult<T> {
    dist: Map<T, number>;
    parent: Map<T, T | undefined>;
  }

  export function dijkstra<T>(graph: Graph<T>, source: T): ShortestPathResult<T>
It's also lightweight, flexible, has familiar C-like syntax, and unlike pseudocode — you can actually run everything.

Re: generics feeling awkward — in TypeScript they feel pretty natural. The type inference helps a lot, you rarely need to spell out type parameters at call sites.


Replies

BloodAndCodetoday at 2:06 PM

[flagged]