this post was submitted on 01 Sep 2023
332 points (96.4% liked)

Programming

17354 readers
439 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities [email protected]



founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 130 points 1 year ago (11 children)

Dynamic typing is insane. You have to keep track of the type of absolutely everything, in your head. It's like the assembly of type systems, except it makes your program slower instead of faster.

[–] [email protected] 1 points 1 year ago* (last edited 1 year ago) (1 children)

I like it in modern PHP, it's balanced. As strict or as loose as you need in each context.

Typed function parameters, function returns and object properties.

But otherwise I can make a DateTime object become a string and vice-versa, for example.

[–] [email protected] 1 points 1 year ago (1 children)

What happens when you coerce a string to a date-and-time but it's not valid?

Where I'm from (Rust), error handling is very strict and very explicit, and that's how it should be. It forces you to properly handle everything that can potentially go wrong, instead of just crashing and looking like a fool.

[–] [email protected] 1 points 1 year ago (1 children)

My point is, you won't ever try. You'd only use "weak" variables inside the function you're working on.

It's explicit when you absolutely need it to be, when the function is being called and you need to know what arguments to pass and what it'll return

[–] [email protected] 1 points 1 year ago (1 children)

A string being parsed as a date-time is presumably user input, which is potentially invalid.

[–] [email protected] 1 points 1 year ago (1 children)

When you say user, you mean a user of a function? In that case PHP would throw a TypeError, and presumably only happens when developing/testing.

If you mean in production, like when submitting a form, an Exception may be thrown. In which case you catch it and return some error message to the user saying the date string is invalid.

[–] [email protected] 1 points 1 year ago (1 children)

By “user” I mean the person who is using the application.

Using exceptions for handling unexceptional errors (like invalid user input) is a footgun. You don't know when one might be raised, nor what type it will have, so you can easily forget to catch it and handle it properly, and then your app crashes.

[–] [email protected] 1 points 1 year ago

you can easily forget to catch it and handle it properly

Even if I coded the form by hand and that happened, it's on me, not on the programming language.

But I don't, I use a framework which handles all that boilerplate validation for me.

load more comments (9 replies)