afilina,
@afilina@phpc.social avatar

Write code in a way where it's impossible for it to be misused by another dev. Prevent instantiating incomplete or incorrect objects, prevent calling methods in the wrong order, prevent putting your objects in an invalid state. This easily quadruples the productivity of my teams.

maaube,

@afilina Amen 🙏 . That’s part of the reasons I’ve grown fond of good type systems. You can literally make invalid states unrepresentable.

sarah,
@sarah@phpc.social avatar

@afilina can you give me an example of how you prevent methods from being called in the wrong order? I’m curious.

gcampax,
@gcampax@mastodon.social avatar

@sarah @afilina for example instead of having two methods on the same object, the first method returns some state object that you need in order to call the second one

mauriciofauth,
@mauriciofauth@phpc.social avatar

@sarah @afilina the way I prevent that is by wrapping the methods calls with another method and call that method instead. And make the previous methods private.

afilina,
@afilina@phpc.social avatar

@mauriciofauth @sarah That's only if you can call both methods one after another without needing input in between. But yes, if I have all the data needed in advance, there no need to have multiple public entry points.

heiglandreas,
@heiglandreas@phpc.social avatar

@sarah @afilina I usually try to have only one method that can get executed to change state.

Or pass a DTO to the method and have it return a changed DTO that can then be used to be chamged in a different method. When those are different DTOs the typesystem will break if called in the wrong order

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • ngwrru68w68
  • rosin
  • GTA5RPClips
  • osvaldo12
  • love
  • Youngstown
  • slotface
  • khanakhh
  • everett
  • kavyap
  • mdbf
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • anitta
  • InstantRegret
  • normalnudes
  • tacticalgear
  • cubers
  • ethstaker
  • modclub
  • cisconetworking
  • Durango
  • provamag3
  • tester
  • Leos
  • megavids
  • JUstTest
  • All magazines