Some developers seem to think that typing is a major bottleneck while programming. It's not.
@Kissaki@feddit.de
link
fedilink
English
41Y

Are people, their critics, really bothered with the writing aspect of verbose code?

Verbose code - and their example shows it quite well - is less concise. To me, their example and reasoning looks more overly verbose, over-engineered rather than well or thoroughly designed and safe.

What makes more sense depends on the context. Where is and will it be used? What is it being exposed to?

A simple data holding class for one “internal” layer to the next can have a very simple form, so it’s easily understood. It may not be safe against misuse or mistakes, but the simplicity and clear use-case and intention much outweighs those costly safeguards to me. For maintainability, for readability, for clarity.

It’s always a balancing act between simplicity and easy understanding vs safeguards and costs. If there’s less risk you can make it much simpler - which reduces other, less obvious risks and costs.


The example made me immediately spot how C# quite a while ago introduced language constructs for what would otherwise be a lot of boilerplate programming like they do in their example.

public record Reservation(DateTimeOffset Date, string Email, string Name, int Quantity, bool IsAccepted);

no need for 78 lines of code with 9 methods.

C# also has the with keyword for copy-adjusting immutable types.

And required init syntax provides another alternative for an effectively immutable type.

public class Reservation
{
    public required DateTimeOffset Date { get; init; }
    public required string Email { get; init; }
    public required string Name { get; init; }
    public required int Quantity { get; init; }
    public required bool IsAccepted { get; init; }
}
Create a post

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 !webdev@programming.dev



  • 1 user online
  • 1 user / day
  • 1 user / week
  • 1 user / month
  • 1 user / 6 months
  • 1 subscriber
  • 1.21K Posts
  • 17.8K Comments
  • Modlog