raspberrypi / pico-examples

BSD 3-Clause "New" or "Revised" License
2.83k stars 820 forks source link

Question about the LCD_1602_i2c #453

Closed hasenradball closed 9 months ago

hasenradball commented 9 months ago

@kilograham Hi,

I am a Software developer. I programed the ESP8266 for many years and I wanted to switch to the pi pico. But if I look into the examples I see many thinks which could be improved to increase:

Lets give threrfore some examples in the code of the lcd_1602_i2c.

code readability

all stuff placed in one file. All lcd constants placed in the main file, where there are not needed.

=> place the constants in a separate header file for example named LCD_Constants.h and include this file. This makes the main file much more cleaner and not so overloaded with things.

code radability / code understandability

Lets take this constants as small example:

Have a look at this definitions:

// commands
const int LCD_CLEARDISPLAY = 0x01;
const int LCD_RETURNHOME = 0x02;
const int LCD_ENTRYMODESET = 0x04;
const int LCD_DISPLAYCONTROL = 0x08;
const int LCD_CURSORSHIFT = 0x10;
const int LCD_FUNCTIONSET = 0x20;
const int LCD_SETCGRAMADDR = 0x40;
const int LCD_SETDDRAMADDR = 0x80;

And then have a look to this ones:

// commands
const int LCD_CLEAR_DISPLAY = 0x01;
const int LCD_RETURN_HOME = 0x02;
const int LCD_ENTRY_MODESET = 0x04;
const int LCD_DISPLAY_CONTROL = 0x08;
const int LCD_CURSOR_SHIFT = 0x10;
const int LCD_FUNCTION_SET = 0x20;
const int LCD_SET_CGRAM_ADDR = 0x40;
const int LCD_SET_DDRAM_ADDR = 0x80;

Which one the these two shots look in the first look more readable without looking twice? Give some constants some spaces in the form of underscores increase the readability much more.

code maintainability / code usage

My personal feeling is writing code examples in cpp style increases the readability, understandability and code adaptation much more. And if this is the case, such SDK become more and more popular. See the Arduino libraries, nearly all libraries uses classes and the benefit of it is also that you can instantiate more than one object (sensor, lcd, etc...) easily.

And in addition the by using objectoriented design the main function became much more smaller which also increases the readability which also increases the maintainability of code. Also code adation is much easier then.

Please see my hints as chance to bring the pico c++ sdk much more up to popularity.

Thanks

Best regards

Frank

peterharperuk commented 9 months ago

Thanks for the feedback