0

I have a C++ interface for video provider. Frames can be rotated (Portrait/Landscape) as a result of platform-specific functions.

enum class EFrameOrientation
{
    KUp, // default orientation
    KDown,
    KLeft,
    KRight
};

Class gives the user info about orientation:

virtual EFrameOrientation getFrameOrientation() { return EFrameOrientation::KUp; }

Also it renders frames it owns with

virtual bool renderCurrentFrame() = 0;
virtual bool renderCurrentFrameWithOrientation() = 0; // STUB TO RENAME

and I added function that handles orientation issues, thus giving a user already EFrameOrientation::KUp-oriented frame.

Non-default orientation is not a bug, it can be desired in some cases.
All below names seem semantically incorrect for me:

renderCurrentFrameRotated // doesn't say it's about orientation
renderCurrentFrameDefaultOriented // which orientation is default: KUp or current?
renderCurrentFrameOrientationFixed // its not bug to fix

How would you choose a good name in this case?
Thanks in advance.

  • 1
    I like distinguishing such versions of things with the "logical"/"physical" contrast. E.g. the headline might logically be at the top of the picture even though it is physically at the bottom because of rotation. – Kilian Foth Oct 25 '17 at 13:42
  • @KilianFoth Thanks! Then how about renderCurrentFrame? It's not an adjective to insert logical. – Olha Pavliuk Oct 25 '17 at 13:45
  • 1
    How does renderCurrentFrameApplyingOrientation sound? – Viktor Seifert Oct 25 '17 at 13:47
  • @ViktorSeifert Sounds very good. :) – Olha Pavliuk Oct 25 '17 at 13:49
  • 1
    @Olia_Pavliuk, The distinction between the two methods would also become more clear when you add an EFrameOrientation argument to renderCurrentFrameWithOrientation. – Bart van Ingen Schenau Oct 26 '17 at 16:22
2

As per Clean Code guidelines method names should clearly state what the method is doing. In this case we have a method which renders a frame but rotates the frame according to some orientation. This rotation is a transformation of the frame. Another term comes to my mind here: we're applying the transformation (rotation/orientation).

The way I understand the question is that it is possible for sub-classes to apply a different orientation, maybe even based on the instance not the class. Therefore I think it would be misleading to include the type of the orientation in the method name.

So my recommendation is to call the method renderCurrentFrameApplyingOrientation since it clearly states that the method renders a frame and applies a transformation (the orientation in this case). I also would recommend calling the other rendering method renderCurrentFrameWithoutApplyingOrientation to make it explicit that the frame will be rendered without applying the transformation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.