Have A Single Source of Truth (In Code!)

Поделиться
HTML-код
  • Опубликовано: 24 окт 2024

Комментарии • 6

  • @KanjiCoder_RTFM
    @KanjiCoder_RTFM 2 месяца назад +1

    The state string looks like a symptom of trying too hard to make "self documenting code"

  • @KanjiCoder_RTFM
    @KanjiCoder_RTFM 2 месяца назад +1

    I think OOP makes it really easy to violate this rule . I used to do it all the time in Actionscript . But never do this in C code .
    I didn't know that was what this rule was called .

    • @SeniorCodeReviewBuddy
      @SeniorCodeReviewBuddy  2 месяца назад +2

      Interesting to hear that you use to do this in Actionscript but don't do it in C code. Do you have any thoughts about what it is in OOP that makes this rule easier to violate?

    • @KanjiCoder_RTFM
      @KanjiCoder_RTFM 2 месяца назад

      @@SeniorCodeReviewBuddy I think there is something about C code that just makes me a more OCD and rigid programmer . Because organizing things well is more your responsibility rather than a language mechanic .
      For example , you need to name space stuff in C , but it's up to you to do it , C won't force you .
      MYLIBRARYNAME_FunctionName( ... )
      Sort of stuff .
      One concrete example of oop making it easier to violate this principle is accidentally instantiating two "singletons" .
      Yes , you can make a type and then only use static class variables . But then it's really weird like... Why do you have an object that is never instantiated ?
      A lot of it could just be co-incidental . I do this mistake almost never because I've been coding forever . And I just co-incidentally happen to prefer C now .
      I would have wrote a shorter letter , but I didn't have enough time .

  • @KanjiCoder_RTFM
    @KanjiCoder_RTFM 2 месяца назад

    I actually like the redundancy of the 2nd example as it could be used to check for bad data .😊

    • @SeniorCodeReviewBuddy
      @SeniorCodeReviewBuddy  2 месяца назад +1

      That is true, depending on how this data is getting generated the redundancy could help detect issues with bad data. But if it's the program itself generating the data (as opposed to loading from another location), I think making it such that we can't generate the equivalent bad data is probably more helpful.