-
using namespace std;
w nagłówku!
- Płaska organizacja projektu (wszystko w głównym katalogu).
- brak pliku projektu! jakiś
cmake
, make
lub przynajmniej coś charakterystycznego dla IDE jakiego używasz.
-
if (cos) return true; else return false
zamiast return cos;
.
- komentarze przy prywatnych metodach a brak komentarzy przy publicznych (co mnie obchodzą prywatne metody, gdy używam klasy)
- brak użycia/wykorzystania forward declaration, np w
SQLConnection.h
powinno być tak:
#ifndef CALENDAR2_SQLCONNECTION_H
#define CALENDAR2_SQLCONNECTION_H
#include <string>
// do przeniesienia do pliku cpp
// #include <cppconn/driver.h>
// #include <cppconn/connection.h>
// #include <cppconn/resultset.h>
// #include <cppconn/statement.h>
// #include <cppconn/exception.h>
#include <vector>
// #include "SQLConnection.h" - plik załącza sam siebie !!!
// do przniesienia do cpp
// #include "Activity.h"
// #include "CalendarEntry.h"
// forward declarations
namesapce sql {
class Driver;
class Connection;
class Statement;
class ResultSet;
class PreparedStatement;
}
class Activity;
class CalendarEntry;
class SQLConnection
{
public:
SQLConnection ();
~SQLConnection ();
void connect ();
void closeConnection ();
void readAllActivitiesToVector ( std::vector < Activity > & );
void readCalendarEntriesToVector ( std::vector < CalendarEntry > &, string );
void deleteActivity ( Activity & );
void addActivity ( Activity & );
void addCalendarEntry ( CalendarEntry & );
void updateCalendarEntry ( CalendarEntry &, int );
private:
sql::Driver *driverPtr;
sql::Connection *connectionPtr;
sql::Statement *statementPtr;
sql::ResultSet *resultSetPtr;
sql::PreparedStatement *preparedStatementPtr;
};
#endif //CALENDAR2_SQLCONNECTION_H
- surowe wskaźniki to anachronizm, używaj
std::unique_ptr
lub std::shared_ptr
- własna kulawa implementacja czasu
MTime
oraz Date
- używaj std::chrono lub ctime, względnie użyj MTime
do opakowania jednego z tych rozwiązań.
- jest jeszcze parę rzeczy, ale na razie sobie daruję
Żeby nie tylko zrzędzić, chwali się, że
- jesteś konsekwentny w formatowaniu kodu
- piszesz małe funkcje
- jak na początkującego to całkiem nieźle