1

I'm trying to improve another abstraction of the serial port. The project involved often needs to check one of the single control signals CTS and DSR. This is currently done by a call to GetCommModemStatus, that's very wordy: a variable is needed and a binary AND operation, GetComModemStatus can also fail (this is more theoretically, but where to check this otherwise...)

I wish to expand the "abstraction" in question by getters for CTS and DSR. And I need help in the decision to make them return bool or int and if the prefix get wouldn't make the resulting code harder to read? Should I use full capitalization?

Here follow some examples of code that would use the new API:

1) with prefix get and boolean result

if (sp.getCts()) {
    // CTS is ON
}

if (!sp.getCts()) {
    // CTS is OFF, in my eyes this looks like getting CTS has failed
}

2) no get prefix with integer result

if (sp.Cts()==1) {
    // CTS is ON
}

if (sp.Cts()==0) {
    // CTS is OFF
}

3) with capitalized CTS (again, no get with bool result)

if (sp.CTS()) {
    // CTS is ON
}

if (!sp.CTS()) {
    // CTS is OFF
}

...this is just to illustrate what I tried in mind; maybe there is even a better solution I left out?

closed as primarily opinion-based by Bart van Ingen Schenau, user22815, Ixrec Dec 4 '15 at 23:29

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.