- 1
- 2
- 3
- 4
- 5
- 6
- 7
public GlobalSetting ReadGlobalSettingById(string id)
{
int totalItems;
var globalSettings = ReadGlobalSettings(PageSetting.All, out totalItems);
return globalSettings.FirstOrDefault(e => e.GlobalSettingID == id);
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1
public GlobalSetting ReadGlobalSettingById(string id)
{
int totalItems;
var globalSettings = ReadGlobalSettings(PageSetting.All, out totalItems);
return globalSettings.FirstOrDefault(e => e.GlobalSettingID == id);
}
Инновационный алгоритм считывания сущности по ID:
1) считываем ВСЕ записи из базы в память;
2) в памяти находим сущность с нужным ID;
3) все остальное пусть Garbage Collector подберет;
4) удобно же, не правда ли?)
−9
Как называется свод правил, к примеру таких, как заключение необязательных параметров программы\функции в квадратные скобки.
Есть ли документ или стандарт на их применение?
Такое часто встречается и в python help, и в man pages, например.
+2
#include <bits/stdc++.h>
using namespace std;
int main(){
int x1,y1,x2,y2;
string xy1,xy2;
cin>>xy1>>xy2;
if (xy1[0]=='A')x1=1;
if (xy1[0]=='B')x1=2;
if (xy1[0]=='C')x1=3;
if (xy1[0]=='D')x1=4;
if (xy1[0]=='E')x1=5;
if (xy1[0]=='F')x1=6;
if (xy1[0]=='G')x1=7;
if (xy1[0]=='H')x1=8;
if (xy1[1]=='1')y1=1;
if (xy1[1]=='2')y1=2;
if (xy1[1]=='3')y1=3;
if (xy1[1]=='4')y1=4;
if (xy1[1]=='5')y1=5;
if (xy1[1]=='6')y1=6;
if (xy1[1]=='7')y1=7;
if (xy1[1]=='8')y1=8;
if (xy2[0]=='A')x2=1;
if (xy2[0]=='B')x2=2;
if (xy2[0]=='C')x2=3;
if (xy2[0]=='D')x2=4;
if (xy2[0]=='E')x2=5;
if (xy2[0]=='F')x2=6;
if (xy2[0]=='G')x2=7;
if (xy2[0]=='H')x2=8;
if (xy2[1]=='1')y2=1;
if (xy2[1]=='2')y2=2;
if (xy2[1]=='3')y2=3;
if (xy2[1]=='4')y2=4;
if (xy2[1]=='5')y2=5;
if (xy2[1]=='6')y2=6;
if (xy2[1]=='7')y2=7;
if (xy2[1]=='8')y2=8;
if ((abs(x1-x2)==1&&abs(y1-y2)==0)||
(abs(x1-x2)==0&&abs(y1-y2)==1)||
(abs(x1-x2)==1&&abs(y1-y2)==1)||
(y1==y2||x1==x2||abs(x1-x2)==abs(y2-y1))||
(y1==y2||x1==x2)||
(abs(x1-x2)==abs(y2-y1))||
(abs(x1-x2)==1&&abs(y1-y2)==2)||
(abs(x1-x2)==2&&abs(y1-y2)==1)||
(x1==x2&&((y1==2&&y2==y1+2)||(y1>=2&&y2==y1+1))))
{
//king
if(abs(x1-x2)==1&&abs(y1-y2)==0)
cout<<"King\n";
else if(abs(x1-x2)==0&&abs(y1-y2)==1)
cout<<"King\n";
else if(abs(x1-x2)==1&&abs(y1-y2)==1)
cout<<"King\n";
//queen
if(y1==y2||x1==x2||abs(x1-x2)==abs(y2-y1))
cout<<"Queen\n";
//rook
if(y1==y2||x1==x2)
cout<<"Rook\n";
//bishop
if (abs(x1-x2)==abs(y2-y1))
cout<<"Bishop\n";
//knight
if(abs(x1-x2)==1&&abs(y1-y2)==2)
cout<<"Knight\n";
else if(abs(x1-x2)==2&&abs(y1-y2)==1)
cout<<"Knight\n";
//pawn
if(x1==x2&&((y1==2&&y2==y1+2)||(y1>=2&&y2==y1+1)))
cout<<"Pawn\n";
}
else cout<<"Nobody";
}
Нашел его в старом добром ACMP и он работает
−6
class Foo {
// ...
private:
std::vector<int> v1_;
std::vector<int> v2_;
void bar( const std::vector<int>& v );
public:
void doAction( int choice ) {
if ( choice == 1 )
bar( v1_ );
else
bar( v2_ );
}
};
Почему передавать поля класса в свои же методы по ссылке\указателю -- это говнокод?
Как этого избегать, чтобы получилось универсальней?
−1
#ifdef DEBUG
static int (*printfn)(FILE *stream, const char *format, ...) = fprintf;
#else
static void (*printfn)(int priority, const char *format, ...) = syslog;
#endif
/* somewhere in getopt() options */
#ifdef DEBUG
printfn = noprintf;
#else
printfn = nosyslog;
#endif
/* elsewhere in a common header file */
#ifdef DEBUG
#undef LOG_ERR
#undef LOG_WARNING
#undef LOG_INFO
#define LOG_ERR stderr
#define LOG_WARNING stderr
#define LOG_INFO stderr
#endif
void nosyslog(int priority, const char *format, ...)
{
(void)priority;
(void)format;
}
int noprintf(FILE *stream, const char *format, ...)
{
(void)stream;
(void)format;
return 0;
}
А попроще способа для --quiet / -DDEBUG нету?
−1
Почему "getElementById", а не "getElementByID"?
0
"SELECT " +
"2 AS recType," +
"1 AS cnt," +
"'' AS vndName," +
"'' AS catName," +
"off.orderBy1S AS orderBy1S," +
"off._id AS _id," +
"off.vendorCode AS vendorCode," +
"off.price AS price," +
"off.currencyId AS currencyId," +
"off.thumbnail AS thumbnail," +
"off.name AS name," +
"IFNULL(crt.quantity,0) AS quantityItem," +
"off.queryRest AS queryRest," +
"off.valueRest AS valueRest," +
"off.lastChangedRest AS lastChangedRest," +
"off.price_uah_ir AS price_uah_ir," +
"IFNULL(vlt.[rate],0) AS rate " + //валютный курс для currencyId товара
"FROM tOffer AS off " +
"LEFT JOIN tCart AS crt ON off.vendorCode=crt.offerId " +
"LEFT JOIN tCurrency AS vlt ON off.currencyId=vlt.valute " +
"WHERE off.vendorName='" + BRAND_NAME + "' AND off.categoryId=" + CATEGORY_ID + " AND (off.name LIKE " + nameFilter + ") " +
"UNION " +
"SELECT " +
"1," +
"COUNT(*)," +
"MAX(vnd.name)," +
"IFNULL(cat.name,'')," +
"0," +
"0," +
"0," +
"0," +
"''," +
"''," +
"vnd.name," +
"0," +
"0," +
"''," +
"''," +
"0," +
"0 " +
"FROM tOffer AS off " +
"LEFT JOIN tVendor AS vnd ON off.vendorName=vnd.name " +
"INNER JOIN tCategory AS cat ON off.categoryId=cat._id " +
"WHERE off.vendorName='" + BRAND_NAME + "' AND off.categoryId=" + CATEGORY_ID + " AND (off.name LIKE " + nameFilter + ") " +
"GROUP BY vnd.name HAVING COUNT(*)>0 " +
"UNION " +
"SELECT " +
"3," +
"COUNT(*)," +
"MAX('Другой товар')," +
"''," +
"0," +
"0," +
"0," +
"0," +
"''," +
"''," +
"'Другой товар'," +
"0," +
"0," +
"''," +
"''," +
"0," +
"0 " +
"FROM tOffer AS off " +
"WHERE off.vendorName<>'" + BRAND_NAME + "' AND (off.name LIKE " + nameFilter + ") " +
"GROUP BY 'Другой товар' HAVING COUNT(*)>0 " +
"UNION " +
"SELECT " +
"4," +
"1," +
"''," +
"''," +
"off.orderBy1S," +
"off._id," +
"off.vendorCode," +
"off.price," +
"off.currencyId," +
"off.thumbnail," +
"off.name," +
"IFNULL(crt.quantity,0)," +
"off.queryRest," +
"off.valueRest," +
"off.lastChangedRest," +
"off.price_uah_ir," +
"IFNULL(vlt.[rate],0) " + //валютный курс для currencyId товара
"FROM tOffer AS off " +
"LEFT JOIN tCart AS crt ON off.vendorCode=crt.offerId " +
"LEFT JOIN tCurrency AS vlt ON off.currencyId=vlt.valute " +
"WHERE off.vendorName<>'" + BRAND_NAME + "' AND (off.name LIKE " + nameFilter + ") " +
"ORDER BY recType,orderBy1S ";
Комменты говорят, что это поиск по бренду и названию
+3
if (x_sum_first_row == 3 || x_sum_second_row == 3 || x_sum_third_row == 3 ||
x_sum_first_column == 3 || x_sum_second_column == 3 || x_sum_third_column == 3 ||
x_sumDiagonalLR == 3 || x_sumDiagonalRL == 3 ||
o_sum_first_row == 3 || o_sum_second_row == 3 || o_sum_third_row == 3 ||
o_sum_first_column == 3 || o_sum_second_column == 3 || o_sum_third_column == 3 ||
o_sumDiagonalLR == 3 || o_sumDiagonalRL == 3)
someoneWon = true;
return someoneWon;
https://codereview.stackexchange.com/questions/125248/java-tic-tac-toe-game-implemented-through-mvc
+2
struct Bar {};
class Foo {
public:
Bar& bar() const { return *bp; }
private:
Bar b;
Bar * const bp = &b;
};
https://wandbox.org/permlink/7JPzrvslrUwbvREb
Как называется данный говнопаттерн?
0
// ...
int datastack [ 4096 ] ;
int *dp = datastack ;
int push ( int x ) {
return *dp++ = x ;
}
int pop() {
return *--dp ;
}
// ...
void execute() {
((void(*)())pop())() ;
}
// ...
Мама! Мама! Я покакал!