I'll start of with and apology for my improper English.
This isn't a problem solving post, more so inquiry on my Arduino library writing skills.
Please provide insight on the code attached below. I would like your thoughts, opinions and concerns on how to refine & fortify the written library (should I include private variables and stuff like that).
If you know a good tutorial/blog/post on how to write better libraries, please do not hesitate to post it here.
#ifndef KYWRD_H
#define KYWRD_H
#define PM pinMode
#define I INPUT
#define I_P INPUT_PULLUP
#define O OUTPUT
#define AR analogRead
#define DR digitalRead
#define AW analogWrite
#define DW digitalWrite
#define H HIGH
#define L LOW
#define Z 0
#endif
CONFIGURATION CPP FILE - purpose of this code is to assign given pins as either INPUT, OUTPUT or INPUT_PULLUP
#include <kywrd.h>
#include <Arduino.h>
#include <cfg.h>
cfg :: cfg () {}
void cfg :: ent ( uint8_t i_p [] ) // function on assigning INPUT to selected pins
{
for ( int i = Z ; i < sizeof ( i_p ) ; i++ )
PM ( i_p [ i ] , I ) ;
}
void cfg :: outp ( uint8_t o_p [] ) // function to assign OUTPUT so selected pins
{
for ( int i = Z ; i < sizeof ( o_p ) ; i ++ )
PM ( o_p [ i ] , O ) ;
}
First of all i had to google what that even means, but now that i know (or at least think so), in what way are the lacking?
I am not writing this library with the intent of public use. I am merely trying to make things easier on myself. I personally believe writing DW instead of digitalWrite is much more time efficient.
Are there perhaps any drawback of using them? As far as i understand the compiler just replaces those words with their listed counterparts while compiling.
makes it look more organised & cleaner which I like.
Perhaps any further thoughts on the core implementation you would like to share (i.e. should I create a private array _i_p / _o_p and use this instead of the actual i_p / o_p array; or stuff like this)?
It is, as long as you're actively working on the project. But if you come back to an earlier project, say, 2 years from now because you want to update some part of it, you have to wade through all kinds of nondescript letter combinations that used to make perfect sense to you one day, but that could mean any number of things today. So you have to go back and forth through your code to track down your own logic from 2 years ago. Trust me, it ain't fun. It really pays off in the end to write code as if you're writing it for other people to understand. If only because 'other people' is going to be you one day down the line!
regarding your code
well ... so much already said... naming things ... just one of your first lines what does .ent() stand for?
Why precompiler defines instead of constexpr?
Why precompiler defines to replace keywords?
Why a class without member variables, why not hand over pins to the class?
Why these blanks?