Logo

dev-resources.site

for different kinds of informations.

Language types for integration safety

Published at
1/16/2024
Categories
api
types
theory
programming
Author
dchaley
Categories
4 categories in total
api
open
types
open
theory
open
programming
open
Author
7 person written this
dchaley
open
Language types for integration safety

In my post on web dev I extolled the virtues of types. Here's an example where static typing would help.

The current implementation of an algorithm I'm refactoring returns a new 64-bit float array for its results. For performance reasons I want to modify the array in-place. This runs awry of type assertions made in the tests. If I modify an int array in-place, I still have ints; the tests assert float.

https://github.com/dchaley/deepcell-imaging/issues/104

If I "just shipped it" – the new type contract maintaining ints – it could break downstream code surprisingly. For instance, somebody probably multiplies the result against an int matrix, expecting to still have floats (float * int = float). And you wouldn't know until it ran… or perhaps, until you noticed it ran incorrectly…

With static types, the compiler tells you, before you ship a thing, that something's gone awry. If you tell it you expect an array of floats, and give it ints, that's an error. Now, there's still plenty of room for generic behavior where types are passed through. Still: the mere existence of this layer provides automatic protection against errors.

In my case I think I can address with parameterization. I need to parameterize editing in-place anyhow. So, people using that new mode, would get the new contract. People using the current mode (return a modified copy) would keep that.

So I get to sidestep the problem in this case and avoid the breaking change. 😎

types Article's
30 articles in total
Favicon
Matanuska ADR 009 - Type Awareness in The Compiler and Runtime
Favicon
Matanuska ADR 007 - Type Semantics for Primary Types
Favicon
Opkey Highlights Importance of Staying Informed About Testing Types for Enhanced Quality Assurance
Favicon
Understanding Next.js and TypeScript Tutorial
Favicon
Python Has Types, They Help
Favicon
YAGNI For Types
Favicon
TypeScript's Lack of Naming Types and Type Conversion in Angular
Favicon
Six Alternatives to Using any in TypeScript
Favicon
Some Types - Part 1
Favicon
Top 9 Essential Utility Types in TypeScript
Favicon
Introduction to TypeScript
Favicon
Error Types in JS
Favicon
Prefer strict types in Typescript
Favicon
Having a type system is more productive
Favicon
Javascript Data Types
Favicon
Simplifying Complex Type Display in TypeScript and VS Code
Favicon
Key Software Testing Types Every QA Needs to Know
Favicon
Understanding and Implementing Type Guards in TypeScript
Favicon
Choosing the Right Database: A Comprehensive Guide to Types and Selection Criteria
Favicon
TypeScript Template Literal Types: Practical Use-Cases for Improved Code Quality
Favicon
Language types for integration safety
Favicon
The cost of types
Favicon
Discriminated Unions
Favicon
Using variant types in ReScript to represent business logic
Favicon
Building React Components Using Unions in TypeScript
Favicon
How to Typescript to JSON with Butlermock
Favicon
Integration Testing Types: A Brief Guide
Favicon
The Benefits of Static Typing: A Developer's Perspective
Favicon
React - Uncaught TypeError: Cannot read properties of undefined (reading 'lat')
Favicon
Conjuring TypeScript's Magic with Mapped Types

Featured ones: