is it necessary to include libraries that are specified in the header file already? I am using the Adafruit BME280 library in my sketch. In the example sketches, they have included the Wire, SPI and the Adafruit_Sensor library. However, I see that in the Adafruit_BME280 library header file, these libraries are already included. So I tried commenting out them in my sketch and it still works. So I wonder if there are still cases or any specific reason to include them twice?
Additionally, if a library is included/referenced twice like mentioned above, wouldn't it increase the size of the sketch unnecessarily?

Example Sketch that comes with the library
#include &lt;Wire.h&gt;
#include &lt;SPI.h&gt;
#include &lt;Adafruit_Sensor.h&gt;
#include &lt;Adafruit_BME280.h&gt;

#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME280 bme; // I2C
//Adafruit_BME280 bme(BME_CS); // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI

unsigned long delayTime;

void setup() {
    Serial.begin(9600);
    while(!Serial);    // time to get serial running
    Serial.println(F(&quot;BME280 test&quot;));

    unsigned status;
    
    // default settings
    status = bme.begin();  
    // You can also pass in a Wire library object like &amp;Wire2
    // status = bme.begin(0x76, &amp;Wire2)
    if (!status) {
        Serial.println(&quot;Could not find a valid BME280 sensor, check wiring, address, sensor ID!&quot;);
        Serial.print(&quot;SensorID was: 0x&quot;); Serial.println(bme.sensorID(),16);
        Serial.print(&quot;        ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n&quot;);
        Serial.print(&quot;   ID of 0x56-0x58 represents a BMP 280,\n&quot;);
        Serial.print(&quot;        ID of 0x60 represents a BME 280.\n&quot;);
        Serial.print(&quot;        ID of 0x61 represents a BME 680.\n&quot;);
        while (1) delay(10);
    }
    
    Serial.println(&quot;-- Default Test --&quot;);
    delayTime = 1000;

    Serial.println();
}


void loop() { 
    printValues();
    delay(delayTime);
}


void printValues() {
    Serial.print(&quot;Temperature = &quot;);
    Serial.print(bme.readTemperature());
    Serial.println(&quot; *C&quot;);

    Serial.print(&quot;Pressure = &quot;);

    Serial.print(bme.readPressure() / 100.0F);
    Serial.println(&quot; hPa&quot;);

    Serial.print(&quot;Approx. Altitude = &quot;);
    Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
    Serial.println(&quot; m&quot;);

    Serial.print(&quot;Humidity = &quot;);
    Serial.print(bme.readHumidity());
    Serial.println(&quot; %&quot;);

    Serial.println();
}
Historically it was necessary, yes. In times past the IDE would look only in your sketch to find the list of libraries to compile and link. However much progress has been made in recursive library searching, whereby the IDE can now find libraries that are included by other libraries.
I am not sure when that change was implemented, but it was a long time coming and is only recently that it's worked.
So if you are distributing code for other people to use then it's a good idea to still add the libraries in the sketch - just in case they're using an older version of the IDE that can't find the libraries included by other libraries.