Obfuscated Object Oriented Programming
-
OOP is for beginners, real software professionals practise OOOP.
When interacting with external hardware, some commands take time. Some other commands take even more time. It's good to have an appropriate timeout just in case the hardware wants to take eternally for a command.
There is a base class like
internal abstract class CommandBase { protected int m_TimeoutForActualResponse; protected ISerialPort m_SerialPort; ... protected CommandBase(ISerialPort _port) { m_SerialPort = _port; m_TimeoutForActualResponse = 7000; ... } protected virtual void ReceiveResponse() { Stopwatch watch = Stopwatch.StartNew(); m_ResponseValues = m_SerialPort.GetBytes(MESSAGE_LENGTH, watch, m_TimeoutForActualResponse); }
Then the focus command took sometimes a little longer. What did Kevin do? Did he change the value of m_TimeoutForActualResponse in the constructor of the FocusCommand?
No, of course not. He overrides the ReceiveResponse function:
protected override void ReceiveResponse() { Thread.Sleep(3000); base.ReceiveResponse(); }
-
Apparently he was inspired by this clbuttic date calculation code:
public Date getTomorrowDate() { Thread.sleep(24 * 3600 * 1000L); return new Date(); }
-
@Kamil-Podlesak I feel like this strategy would be effective for getting yesterday's date, but not tomorrow's
-
@ben_lubar Nah, just needs a -24h sleep between the
new Date()
and thereturn
to counteract the side-effect.
-
@PleegWat You just have to wait it out... backwards
-
@hungrier how do you
Thread.sleep
with boxing gloves on
-
@ben_lubar said in Obfuscated Object Oriented Programming:
@Kamil-Podlesak I feel like this strategy would be effective for getting yesterday's date, but not tomorrow's
It gets, tomorrow, the date.
-
Let's add a new gem of Obfuscated Object Oriented Programming.
Copyright by Kevin, of course.internal partial class DbCleaner : PanoramaCleaner, IDbCleaner { private IPanoramaCleaner PanoramaCleaner { get; set; }
You see,
DbCleaner
is aPanoramaCleaner
, but just in case you need to make sure your colleagues cannot understand what you are doing, there is a private property which can be set during configuration where you can provide it with an extraIPanoramaCleaner
.Of course,
DbCleaner
is not some kind ofDecorator
around anIPanoramaCleaner
. In some occasions, Kevin explicitly passesthis
instance to some instance methods, and afterwards prefers the property:CleanDates(_protectedEvents, keepDate, _panoramaClaner:this); if (PanoramaCleaner != null) { CleanDates(_protectedEvents, keepDate, PanoramaCleaner); }
Now let's hope Kevin gets a clean date...
But Bernie needs a
BrainCleaner
now.
-
@BernieTheBernie said in Obfuscated Object Oriented Programming:
Copyright by Kevin, of course.
There's your problem.