• 3 Posts
  • 53 Comments
Joined 1 year ago
cake
Cake day: June 19th, 2023

help-circle
  • This doesn’t seem overly useful.

    It’s a list taken out of a bunch of books with no regard for how something can be the best path in one language and a smell in another language.

    Look at this page for example: https://luzkan.github.io/smells/imperative-loops

    It suggests using functional loop methods (.map(), .reduce(), .filter()) instead of using imperative loops (for, for in, for each) but completely disregards the facts that imperative loops also have access to the break, continue, and return keywords to improve performance.

    For example: If I have an unsorted list of 1000 cars which includes a whole bunch of information per car (e.g. color, year manufactured, etc…), and I want to know if there were any cars were manufactured before the year 1980, I can run an imperative loop through the list and early return true if I find one, and only returning false if I haven’t found one by the end of the list.

    If the third car was made in 1977, then I have only iterated through 3 cars to find my answer.

    But if I were to try this with only functional loops, I would have to iterate through all 1000 cars before I had my answer.

    A website with blind rules like this is going to lead to worse code.







  • I’m under the impression that there’s two reasons we don’t have it in chromium yet:

    1. Google initially ignored jpeg-xl but then everyone jumped on it and now they feel they have to create a post-hoc justification for not supporting it earlier which is tricky and now they have a sunk cost situation to keep ignoring it
    2. Google today was burnt by the webp vulnerability which happened because there was only one decoder library and now they’re waiting for more jpeg-xl libraries which have optimizations (which rules out reference implementations), good support (which rules out libraries by single authors), have proven battle-hardening (which will only happen over time) and are written safely to avoid another webp style vulnerability.

    Google already wrote the wuffs language which is specifically designed to handle formats in a fast and safe way but it looks like it only has one dedicated maintainer which means it’s still stuck on a bus factor of 1.

    Honestly, Google or Microsoft should just make a team to work on a jpg-xl library in wuffs while adobe should make a team to work on a jpg-xl library in rust/zig.

    That way everyone will be happy, we will have two solid implementations, and they’ll both be made focussing on their own features/extensions first so we’ll all have a choice among libraries for different needs (e.g. browser lib focusing on fast decode, creative suite lib for optimised encode).









  • It sounds like to me that you’ve taken your knowledge of your commonly used languages for granted, and assumed a new language would be just as easy. But if you watch a developer who is dipping their toe into that ecosystem for the first time you’ll find them making mistakes and running into footguns you didn’t know were possible.

    Regardless of the language, not having a proper guide leaves devs susceptible to the incorrect blogospam that’s out there, where engagement is rewarded over correctness.

    Ignore all of the blogospam.

    The two things you need to know:

    1. C/C++/Java/Go/Python have all gone through changes, growth and churn just like JS.
    2. Knowing the history of the ecosystem will go a long way towards helping you. If you understand why things have changed, then you’ll know how to ignore the bad advice out there.

    Here’s my shortened version of number 2.

    The beginning:

    • JS starts as a scripting language embedded into a browser
    • Different browsers try to copy each other but put in their own “features” pulling the language in different directions.
    • The amorphous blob that is JS starts to congeal and language standards are solidified. This standard is known as ECMAScript (named for legal reasons). ES1 is the first version, followed by ES2 and ES3, each adding useful features.
    • ES3 (released in 1999):
      • This is what you could consider the first long term stable baseline widely supported version of the language, where you can make anything you want.
      • Almost everything you can make in future versions of the language can be backported to ES3.
      • If you want to go by analogy, you can think of ES3 as javascript’s C99.

    The false start:

    • Work starts on ES4 with a massive feature list (including static typing, classes, modules, algebraic data types, generators, embedded xml/xhtml known as JSX/TSX today, etc…). It fails due to political infighting, and for basically being too ambitious in a single version.
      • This sucks up years of progress between released versions.
      • This version is commonly seen as being poisoned by 90’s/00’s Micro$oft and the dark ages of Internet Explorer
      • But the spirit of ES4 was released spread out over future versions anyway.

    The resumption:

    • The v8 JS engine is released, making JS really fast and worth programming in. This is used in Chrome and Node.
    • ES5 (released in 2009):
      • Adds native json support, reflection, and a strict mode to avoid some footguns with ES3
      • Think of this as C11
      • Some developers being experimenting with a more consise syntax in CoffeeScript that compiles down to ES5.
    • 2012: Typescript is released adding an optional and gradual typing system to JS (inspired by C# and ES4) designed for both Humans and Computers.
      • In effect, this brings IDE-style support for JS
    • ES6 (released in 2015):
      • With the lessons learned from CoffeeScript, a whole bunch of syntactical sugar is added to make the language more pleasant to write in.
      • With the lessons learned from community made modules, an official module spec is released and added to the language.
        • Known as ESM (EcmaScript Modules)
        • The community starts moving away from unofficial modules (CJS, AMD, UMD)
      • Babel is created to allow any developer to create and share their their own language extensions.
        • The faster feedback cycle from Babel allows for smaller and more frequent language updates.
        • Javascript moves to a yearly release cycle and ES6 is renamed ES2015
    • ES2016
      • Adds block scoping as an alternative to hoisting
    • ES2017
      • Adds async/await/Promise() syntax sugaring, to make asynchronous programming easier
    • ES2018
      • Adds ... (rest/spread operator) syntax sugaring, to make destructuring and variadic functions easier
      • Ryan Dhal (creator of Node) releases his famous 10 Things I Regret About Node.js talk. Announces his intention to create a “modern reset” of Node known as Deno.
    • ES2019
      • Minor changes
      • Deno is released
    • ES2020
      • Adds ?? Nullish coalescing operator syntax sugaring
    • ES2021
      • Adds ??=/&&=/||= Logical assignment syntax sugaring
    • ES2022
      • Adds top level await, making asynchronous programming easier
      • Adds private field syntax sugaring
    • ES2023
      • Minor changes

    The current state of things

    • Language-wise

      • Javascript has added a whole bunch of syntactical sugar since 2009 making it really pleasant to code in.
      • Typescript adds some really nice IDE support to Javascript and the vast majority of all libraries and frameworks are written in it giving that IDE support to Javascript developers.
      • Babel allows developers to create their own language extensions, which are frequently put forwards at for other developers to give feedback on. Useful proposals are added to the language on a yearly basis.
    • Runtime-wise

      • Node is considered the older slow-moving most-stable release of running JS outside of the browser
        • Think Debian
      • Deno is considered the friendly Node, coming with all the tools a developer needs (linter, bundler, tester, ts support, etc…). In the last 5 years it has reached almost complete feature parity and compatibility with Node.
        • Think Ubuntu
      • Bun is a brand new kid on the block prioritising speed over compatibility.
        • Think nightly linux
    • Standard workflow

      • Write in typescript
      • Let your editor check your typescript while you’re typing live so you don’t need to go through a compile cycle
      • Let your project’s stack compile your typescript for you.
        • If you’re writing a new project from scratch, Deno will run typescript for you.
        • If you want to build a new stack from scratch with no assistance, use the typescript project itself to check and compile your code into js, or use esbuild to strip out the typescript types to turn your typescript into js. (most developers elect to strip types since your editor/ide should be live checking your typescript anyway allowing you to skip a redundant compile check cycle)
        • If you’re using an existing stack, your build tools will compile/strip-out typescript for you.
    • Tooling wise

      • Most projects use Vite / rollup / and other “zero-config” tools to build and bundle their applications. Some older projects still use Webpack (which does the same thing, but with a more complicated config file).
      • Everyone uses ESM modules now, almost no one uses the older modules.

    For your simple fibonacci example:

    1. Create your fibonacci module that exports your fibonacci function
    2. Import module
    3. Call function in module
    4. Pick your endpoint:
    • Browser endpoint: Output result in console.log() and see result in browser’s console.
    • Server-side endpoint: Output result in Deno.serve() and see result in network requests/responses
    • CLI endpoint: Output result in console.log() and see result in terminal

  • This comment just seems weird no matter which angle I try to approach it from.

    immature tooling ecosystem

    It’s over a decade old now. I wouldn’t call that immature.

    Looking at your linked comment…

    following a basic tutorial somehow ended up spending multiple seconds just to transpile and run “Hello, World!”.

    1. Install deno
    2. Create hello.ts containing: console.log("hello world");
    3. deno run hello.ts (time taken to run command: 0.037s)

    […] 3 different ways of specifying the files and settings you want to use […] 3 incompatible ways to define and use a “module”

    Yes, that tends to happen as ecosystems evolve over time. Typescript allows developers to use modern standards-compliant modules, while maintaining backwards compatibility for older code.

    embracing duck typing means […]

    One of typescript’s strengths is that its type system isn’t all or nothing. Typescript will support duck typers, but it isn’t forced or limited to that. You can add as much or as little typing as you want. In theory, this means that the language supports simple beginners up to experts creating turing-complete theorem solvers at compile time. In practice, this means a much smoother onboarding and porting experience.

    Have a “generalized fibonacci” module taking 3 inputs […]

    I’m not sure if this is the basic problem challenge or the hello world example was. It seems a bit ambiguous as to what you really want, but it’s easy to create a module that takes inputs and produces outputs while running on backend servers, in browsers, and in CLIs.