- 1
- 2
- 3
- 4
- 5
- 6
public List<OrderEntity> getOrders() {
if (orders == null) {
orders = new ArrayList<OrderEntity>();
}
return orders;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+148
public List<OrderEntity> getOrders() {
if (orders == null) {
orders = new ArrayList<OrderEntity>();
}
return orders;
}
Потокобезопасность? Не, не слышал.
+160
uint64_t search(StringList& who, const string& aName, const string& aSize,TypeModes aTypeMode, SizeModes aSizeMode, const string& aToken, const StringList& aExtList, void* aOwner = NULL)
{
return search(who, aName, Util::toInt64(aSize), aTypeMode, aSizeMode, aToken, aExtList,aOwner);
}
А теперь небольшой _опрос_ :
Каково, по вашему мнению, необходимое и достаточное
качество и количество параметров метода/функции, при котором необходимо(по самым разным причинам) объединять их(параметры) в _меньшее_количество_ , используя встроенные/пользовательские типы данных.
Например: https://github.com/negativ/eiskaltdcpp/blob/master/dcpp/SearchManager.h
−101
switch (level)
{
case 1:
{
loadLevel1();
break;
}
case 2:
{
loadLevel2();
break;
}
case 3:
{
loadLevel3();
break;
}
default:
loadLevel0();
break;
}
Я умею передавать процедурам параметры перед скобкой!
+160
function bigplus(){
$args = func_get_args();
$maxlength = 0;
$mlkey = 0;
$inmind = 0;
foreach($args as $key=>$arg){
$args[$key] = array_reverse(str_split($arg));
$length = count($args[$key]);
if($maxlength<$length){
$maxlength = $length;
$mlkey = $key;
}
}
for($pos=0; $pos<$maxlength; $pos++){
$c = 0;
for($i=0; $i<count($args); $i++){
if(!isset($args[$i][$pos])){
$args[$i][$pos]=0;
}
$c+=$args[$i][$pos];
}
$args[0][$pos] = $c+$inmind;
$inmind = floor(($args[0][$pos])/10);
$args[0][$pos] %= 10;
}
if($inmind>0){
$args[0][] = $inmind;
}
return implode(array_reverse($args[0]));
}
Народ, знаю что говнокод, помогите советом как исправить?
Функция выводит результат сложения любого числа положительных чисел произвольной длины.
Не придумал ничего умнее, чем реализовать сложение "в столбик".
−178
SELECT DISTINCT BE.ID as ID,BE.NAME as NAME,BE.IBLOCK_ID as IBLOCK_ID,BE.IBLOCK_SECTION_ID as IBLOCK_SECTION_ID, FPEN0.VALUE as PROPERTY_TYPE_LAMP_VALUE, FPEN0.ID as PROPERTY_TY
PE_LAMP_ENUM_ID, FPV0.ID as PROPERTY_TYPE_LAMP_VALUE_ID, FPEN1.VALUE as PROPERTY_STYLE_VALUE, FPEN1.ID as PROPERTY_STYLE_ENUM_ID, FPV1.ID as PROPERTY_STYLE_VALUE_ID,BE.PREVIEW_PICTURE as PREVIEW_PICTURE, FPEN2.VALUE as PROPERTY_SERIES_VALUE, FPEN2.ID as PROPERTY_SERIES_ENUM_ID, FPV2.ID as PROPERTY_SERIES_VALUE_ID, FPEN3.VALUE as PROPERTY_COLOR_ARMAT_VALUE, FPEN3.ID as PROPERTY_COLOR_ARMAT_ENUM_ID, FPV3.ID as PROPERTY_COLOR_ARMAT_VALUE_ID, FPEN4.VALUE as PROPERTY_COLOR_PLAFON_VALUE, FPEN4.ID as PROPERTY_COLOR_PLAFON_ENUM_ID, FPV4.ID as PROPERTY_COLOR_PLAFON_VALUE_ID, FPEN5.VALUE as PROPERTY_NEW_VALUE, FPEN5.ID as PROPERTY_NEW_ENUM_ID, FPV5.ID as PROPERTY_NEW_VALUE_ID, FPEN6.VALUE as PROPERTY_SALE_VALUE, FPEN6.ID as PROPERTY_SALE_ENUM_ID, FPV6.ID as PROPERTY_SALE_VALUE_ID , CAT_P1.ID as CATALOG_PRICE_ID_1, CAT_P1.CATALOG_GROUP_ID as CATALOG_GROUP_ID_1, CAT_P1.PRICE as CATALOG_PRICE_1, CAT_P1.CURRENCY as CATALOG_CURRENCY_1, CAT_P1.QUANTITY_FROM as CATALOG_QUANTITY_FROM_1, CAT_P1.QUANTITY_TO as CATALOG_QUANTITY_TO_1, '<C1><E0><E7><EE><E2><E0>
<FF> <F6><E5><ED><E0>' as CATALOG_GROUP_NAME_1, 'Y' as CATALOG_CAN_ACCESS_1, 'Y' as CATALOG_CAN_BUY_1, CAT_P1.EXTRA_ID as CATALOG_EXTRA_ID_1, CAT_PR.QUANTITY as CATALOG_QUANTITY, CAT_PR.QUANTITY_TRACE as CATALOG_QUANTITY_TRACE, CAT_PR.WEIGHT as CATALOG_WEIGHT, CAT_VAT.RATE as CATALOG_VAT, CAT_PR.VAT_INCLUDED as CATALOG_VAT_INCLUDED, CAT_PR.PRICE_TYPE as CATALOG_PRICE_TYPE, CAT_PR.RECUR_SCHEME_TYPE as CATALOG_RECUR_SCHEME_TYPE, CAT_PR.RECUR_SCHEME_LENGTH as CATALOG_RECUR_SCHEME_LENGTH, CAT_PR.TRIAL_PRICE_ID as CATALOG_TRIAL_PRICE_ID, CAT_PR.WITHOUT_ORDER as CATALOG_WITHOUT_ORDER, CAT_PR.SELECT_BEST_PRICE as CATALOG_SELECT_BEST_PRICE
FROM b_iblock B
INNER JOIN b_lang L ON B.LID=L.LID
INNER JOIN b_iblock_element BE ON BE.IBLOCK_ID = B.ID
LEFT JOIN b_iblock_property FP0 ON FP0.IBLOCK_ID = B.ID AND FP0.CODE='TYPE_LAMP'
INNER JOIN b_iblock_property FP1 ON FP1.IBLOCK_ID = B.ID AND FP1.CODE='STYLE'
INNER JOIN b_iblock_property FP2 ON FP2.IBLOCK_ID = B.ID AND FP2.CODE='SERIES'
LEFT JOIN b_iblock_property FP3 ON FP3.IBLOCK_ID = B.ID AND FP3.CODE='COLOR_ARMAT'
LEFT JOIN b_iblock_property FP4 ON FP4.IBLOCK_ID = B.ID AND FP4.CODE='COLOR_PLAFON'
LEFT JOIN b_iblock_property FP5 ON FP5.IBLOCK_ID = B.ID AND FP5.CODE='NEW'
LEFT JOIN b_iblock_property FP6 ON FP6.IBLOCK_ID = B.ID AND FP6.CODE='SALE'
/*... тут еще 14 джоинов ...*/
INNER JOIN (
SELECT DISTINCT BSE.IBLOCK_ELEMENT_ID
FROM b_iblock_section_element BSE
INNER JOIN b_iblock_section BS ON BSE.IBLOCK_SECTION_ID = BS.ID
WHERE (((BS.ID = 25)))
) BES ON BES.IBLOCK_ELEMENT_ID = BE.ID
LEFT JOIN b_catalog_price CAT_P1 ON (CAT_P1.PRODUCT_ID = BE.ID AND CAT_P1.CATALOG_GROUP_ID = 1)
LEFT JOIN b_catalog_product CAT_PR ON (CAT_PR.ID = BE.ID)
LEFT JOIN b_catalog_iblock CAT_IB ON ((CAT_PR.VAT_ID IS NULL OR CAT_PR.VAT_ID = 0) AND CAT_IB.IBLOCK_ID = BE.IBLOCK_ID)
LEFT JOIN b_catalog_vat CAT_VAT ON (CAT_VAT.ID = IF((CAT_PR.VAT_ID IS NULL OR CAT_PR.VAT_ID = 0), CAT_IB.VAT_ID, CAT_PR.VAT_ID))
WHERE 1=1
AND ( 13:19
((((BE.IBLOCK_ID = '3'))))
AND ((((BE.ACTIVE='Y'))))
AND (
(
((((CAT_P1.PRICE >= '386'))))
)
AND (
((((CAT_P1.PRICE <= '4166'))))
)
)
AND ((((CAT_PR.QUANTITY > '0'))))
AND ((((FPEN1.VALUE LIKE '<CA><EB><E0><F1><F1><E8><F7><E5><F1><EA><E8><E9>'))))
AND ((((FPEN2.VALUE LIKE 'Davoli'))))
)
AND (((BE.WF_STATUS_ID=1 AND BE.WF_PARENT_ELEMENT_ID IS NULL)));
Bitrix, что еще тут скажешь))
+106
function IsRunningWithAdminPrivs: Boolean;
begin
var
List: TStringList;
begin
List := TStringList.Create;
try
try
List.Text := 'Sample';
// Use SHGetFolder path to retreive the program files folder
// here is hardcoded for the sake of the example
List.SaveToFile('C:\program files\test.txt');
Result := True;
except
Result := False;
end;
finally
List.Free;
DeleteFile('C:\program files\test.txt');
end;
end;
Нуфф Саид
+144
public static const INFINITY:int = 100000;
а вы говорите, что скорость света недостижима... Вон, мы даже уже бесконечность обозначили!
+111
[WebMethod]
public PackageHoldResult RegisterHold(
string login,
string password,
PackageHoldRequest holdRequest)
{
PackageHoldResult result = new PackageHoldResult();
result.ResultCode = 0;
try
{
// ...
}
catch
{
result.ResultCode = (int) PackageHoldRequestResultCode.InternalError;
}
return result;
}
Логирование?... что это?
−92
def get_next_line(max_level, current_level, current_line_items)
next_line_items = []
result_string = ''
if current_level == 1
next_line_items.push(1)
result_string = "1\n"
else
current_line_number = false
current_line_number_count = 0
current_index = 0
current_line_items.each do |line_number|
if current_index == 0
current_line_number = line_number
current_line_number_count = 1
else
if line_number == current_line_number
current_line_number_count = current_line_number_count + 1
else
next_line_items.push(current_line_number_count)
next_line_items.push(current_line_number)
current_line_number_count = 1
current_line_number = line_number
end
end
if current_index >= current_line_items.length - 1
next_line_items.push(current_line_number_count)
next_line_items.push(current_line_number)
end
current_index = current_index + 1
end
result_string = next_line_items.join(' ') + "\n"
end
if current_level < max_level
result_string = result_string + get_next_line(max_level, current_level + 1, next_line_items).to_s
end
# return result
result_string
end
puts 'Input max level:'
level = gets
puts ''
puts get_next_line(level.to_i, 1, [])
реальное тестовое задание кандитата.
задача - вывести несколько членов последовательности
1
11
21
1211
....
+144
string buf;
...
char c_buf[MAX_LEN];
strncpy(c_buf, buf.c_str(), MAX_LEN);
в чём ошибка?