跳过导航
Stop writing utility classes.
0:00 / 0:48

Stop writing utility classes.

Gautier 💙

@mcflyDev1万 位关注者

在 X 上查看
135 个赞下载原帖

19,626 次观看

Stop writing utility classes. Utility classes are a sign that you are writing procedural code. You should avoid them. Instead, write a real object model. For example, an email is not a String... It's an Email. Gautier - 🤘

11 条评论

评论来自 X (Twitter) 上的原帖

  • Christian Findlay 的头像

    @CFDevelop

    I don’t write utility classes I write utility functions 👌

    5 个赞

  • PDF GPT 的头像

    @pdfgptsupport

    Everyone is getting ahead with AI. You should be too. Summarize documents, craft emails, and generate custom content instantly with this powerful tool. It's like having ChatGPT tailored for your job. Try it for free.

    13,783 个赞

  • Rody Davis 的头像

    @rodydavis

    Probably a good use of extension types for Email to implement String and also still provide validate methods.

    4 个赞

  • Francesco Vallone 的头像

    @francescovll

    In my opinion another approach is to use a validation library like Acanthis that will still remove the need for a utility class, while providing validation and parsing of the object. Everything is just a line of code string().email()

    4 个赞

  • Cillian Myles 的头像

    @IdiomaticBytes

    You didn’t give a concrete reason why your approach is better? Same validation everywhere? I don’t think that’s guaranteed any more than that a user imports the same util class everywhere. 🤔

    3 个赞

  • Nnaemeka Sidney 的头像

    @sidswipe

    .isEmail

    2 个赞

  • Dany | Mobile & Game Dev 🍉 的头像

    @yasfdany

    Ohhh I like this

    1 个赞

  • Gautier 💙 的头像

    @mcflyDev

    🤘🏻

  • AbdulAzeez 的头像

    @dev_azeez

    Nice

    1 个赞

  • jayson.kt 的头像

    @idiomaticdev

    it's not an email until after it's validated. it's a wannabe

    1 个赞

  • Pangz (pangz.vrsc@) 的头像

    @PangzLab

    It doesn't add any value modeling the email as a different class instead of just leaving it by default as a string. You're using unnecessary resources just to wrap a simple string to a class just to make it appear as an object. You only need to validate it and that's it.(just my 2 cents)

    1 个赞