- 1
bool isNoGoodCommentText = String.IsNullOrEmpty(this.txbxCommentCtrl.Text) || String.IsNullOrWhiteSpace(this.txbxCommentCtrl.Text);
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1
bool isNoGoodCommentText = String.IsNullOrEmpty(this.txbxCommentCtrl.Text) || String.IsNullOrWhiteSpace(this.txbxCommentCtrl.Text);
И действительно, is not good
−2
float PriceByProductID(string product_id)
{
if(product_id == RUBY_PILE)
return 1.99f;
else if (product_id == RUBY_BAG)
return 4.99f;
else if (product_id == RUBY_SACK)
return 9.99f;
else if (product_id == RUBY_BOX)
return 19.99f;
else if (product_id == RUBY_CHEST)
return 39.99f;
else if (product_id == RUBY_TRUNK)
return 99.99f;
else if (product_id == GOLD_PILE)
return 0.99f;
else if (product_id == GOLD_BAG)
return 2.99f;
else if (product_id == GOLD_SACK)
return 7.99f;
else if (product_id == GOLD_BOX)
return 14.99f;
else if (product_id == GOLD_CHEST)
return 29.99f;
else if (product_id == GOLD_TRUNK)
return 79.99f;
return 0f;
}
−1
mId = core.Material.Materials.FirstOrDefault(x => x.Value.article == m.article && x.Value.title == m.title && x.Value.category_id == m.category_id).Key;
if (mId == 0)
mId = core.Material.Materials.FirstOrDefault(x => x.Value.article == m.article && x.Value.title == m.title).Key;
if (mId == 0)
mId = core.Material.Materials.FirstOrDefault(x => x.Value.article == m.article && x.Value.category_id == m.category_id).Key;
if (mId == 0)
mId = core.Material.Materials.FirstOrDefault(x => x.Value.title == m.title && x.Value.category_id == m.category_id).Key;
if (mId == 0)
mId = core.Material.Materials.FirstOrDefault(x => x.Value.article == m.article).Key;
if (mId == 0)
mId = core.Material.Materials.FirstOrDefault(x => x.Value.title == m.title).Key;
Есть 3 поля.
Поиск сначала по 3. Затем по 2, затем по 2 и еще по 2. И от безысходности по 1
Реально ли это оптимизировать?
−1
Func<int,int> fact = (int i_in) => i_in;
fact = (int i_in) =>
{
if (i_in>1) return (fact(i_in-1)*i_in);
else return (1);
};
+2
public ActionResult Exception()
{
throw new Exception("You better not to execute this!");
}
нашел говнокод, оставленный прошлым архитектором)
0
<cms:CMSWebPartZone ZoneID="AnalZone" runat="server" />
ASP.NET, аналитика
+2
switch (button.Tag.ToString()) {
case "Ezp":
{
if (nowLayer.OpenedFiles.Count == 0)
{
nowLayer.OpenedFiles = new List<ExemplarFile> { new ExemplarFile("") };
}
if (nowLayer.OpenedFiles[0].EdinZemleps == null)
{
nowLayer.OpenedFiles[0].EdinZemleps = new List<EdinZemlep>();
}
var strName = ":ЕЗ" + (nowLayer.OpenedFiles[0].EdinZemleps.Count + 1);
nowLayer.OpenedFiles[0].EdinZemleps.Add(new EdinZemlep(strName) { Status = StatusEnum.Образуемый });
_ezpListTreeView.Add(new EzpTreeView { NameEzp = strName, ContourList = new List<ContourTreeView>(), ParcelList = new List<PartZuTreeView>(), IsEzpVisible = true, IsSelectedEzp = false } );
_dictionaryEzpTreeViewFile.Add(_ezpListTreeView[_ezpListTreeView.Count - 1], nowLayer.OpenedFiles[0]);
_dictionaryEzpTreeViewEdinZemlep.Add(_ezpListTreeView[_ezpListTreeView.Count - 1], nowLayer.OpenedFiles[0].EdinZemleps[nowLayer.OpenedFiles[0].EdinZemleps.Count - 1]);
break;
}
case "ContourEzp":
{
indexEz = TreeViewStackPanelMain.Children.IndexOf(((button.Parent as Grid).Parent as StackPanel).Parent as Grid) - _partZuListTreeView.Count;
var strName = (nowLayer.OpenedFiles[0].EdinZemleps[indexEz].CadNum != "" ? nowLayer.OpenedFiles[0].EdinZemleps[indexEz].CadNum : nowLayer.OpenedFiles[0].EdinZemleps[indexEz].LastName) + "(" + (nowLayer.OpenedFiles[0].EdinZemleps[indexEz].Contours.Count + 1) + ")";
nowLayer.OpenedFiles[0].EdinZemleps[indexEz].AddContour(new Contour(strName) { Status = StatusEnum.Образуемый });
if (_ezpListTreeView[indexEz].ContourList == null)
{
_ezpListTreeView[indexEz].ContourList = new List<ContourTreeView>();
}
strName = nowLayer.OpenedFiles[0].EdinZemleps[indexEz].Contours.Last().Name;
_ezpListTreeView[indexEz].ContourList.Add(new ContourTreeView { NameContour = strName, IsContourVisible = true, IsSelectedContour = false } );
for (var i = 0; i < _ezpListTreeView[indexEz].ContourList.Count; i++)
{
_ezpListTreeView[indexEz].ContourList[i].NameContour = nowLayer.OpenedFiles[0].EdinZemleps[indexEz].Contours[i].Name;
}
break;
}
case "ZuEzp":
{
indexEz = TreeViewStackPanelMain.Children.IndexOf(((button.Parent as Grid).Parent as StackPanel).Parent as Grid) - _partZuListTreeView.Count;
var strName = ":ЗУ" + (nowLayer.OpenedFiles[0].EdinZemleps[indexEz].Parcels.Count + 1);
if (_ezpListTreeView[indexEz].ParcelList == null)
{
_ezpListTreeView[indexEz].ParcelList = new List<PartZuTreeView>();
}
nowLayer.OpenedFiles[0].EdinZemleps[indexEz].Parcels.Add(new Parcel(strName) { Status = StatusEnum.Образуемый });
_ezpListTreeView[indexEz].ParcelList.Add(new PartZuTreeView { NamePartZu = strName, ContourList = new List<ContourTreeView>(), PartList = new List<PartTreeView>(), IsPartZuVisible = true, IsSelectedPartZu = false });
_dictionaryPartZuTreeViewFile.Add(_ezpListTreeView[indexEz].ParcelList[_ezpListTreeView[indexEz].ParcelList.Count - 1], nowLayer.OpenedFiles[0]);
_dictionaryPartZuTreeViewParcel.Add(_ezpListTreeView[indexEz].ParcelList[_ezpListTreeView[indexEz].ParcelList.Count - 1], nowLayer.OpenedFiles[0].EdinZemleps[indexEz].Parcels[nowLayer.OpenedFiles[0].EdinZemleps[indexEz].Parcels.Count - 1]);
break;
}
case "PartZuEzp":
{
indexEz = TreeViewStackPanelMain.Children.IndexOf(((((((button.Parent as Grid).Parent as StackPanel).Parent as Grid).Parent as StackPanel).Parent as Grid).Parent as StackPanel).Parent as Grid) - _partZuListTreeView.Count;
indexZu = ((((((button.Parent as Grid).Parent as StackPanel).Parent as Grid).Parent as StackPanel).Parent as Grid).Parent as StackPanel).Children.IndexOf((((((button.Parent as Grid).Parent as StackPanel).Parent as Grid).Parent as StackPanel).Parent as Grid));
var sbPrclName = nowLayer.OpenedFiles[0].EdinZemleps[indexEz].Parcels[indexZu].LastName + "/чзу" + (nowLayer.OpenedFiles[0].EdinZemleps[indexEz].Parcels[indexZu].Subparcels.Count + 1);
nowLayer.OpenedFiles[0].EdinZemleps[indexEz].Parcels[indexZu].Subparcels.Add(new Subparcel(sbPrclName) { Status = StatusEnum.Образуемый });
if (_ezpListTreeView[indexEz].ParcelList[indexZu].PartList == null)
{
_ezpListTreeView[indexEz].ParcelList[indexZu].PartList = new List<PartTreeView>();
}
_ezpListTreeView[indexEz].ParcelList[indexZu].PartList.Add(new PartTreeView { NamePart = sbPrclName, ContourList = new List<ContourTreeView>(), IsPartVisible = true, IsSelectedPart = _ezpListTreeView[indexEz].ParcelList[indexZu].IsSelectedPartZu });
_dictionaryPartTreeViewSubparcel.Add(_ezpListTreeView[indexEz].ParcelList[indexZu].PartList[_ezpListTreeView[indexEz].ParcelList[indexZu].PartList.Count - 1], nowLayer.OpenedFiles[0].EdinZemleps[indexEz].Parcels[indexZu].Subparcels[nowLayer.OpenedFiles[0].EdinZemleps[indexEz].Parcels[indexZu].Subparcels.Count - 1]);
break;
}
и это продолжается, продолжается и продолжается....
−1
if (string.IsNullOrWhiteSpace(frmDelegatorLogin.ViewModel.Username))
throw new Exception("Не введен логин");
if (dbEmployee == null)
throw new Exception(string.Format("Не найден пользователь с логином \"{0}\"", frmDelegatorLogin.ViewModel.Username));
if (dbEmployee.DelegatePassword != frmDelegatorLogin.ViewModel.Password)
throw new Exception("Указан неверный пароль");
Вот такой вот новый метод валидации полей. Да, логин и пароль вводятся текстом, да, Exception потом ничем не ловится и пользователь получает unhandeled exception...
+3
protected override void mergeModels(IStuff Stuff, IStuff With)
{
var stuff = (MyObject)Stuff;
var with = (MyObject)With;
if (with.title != null)
stuff.title = with.title;
if (with.description != null)
stuff.description = with.description;
if (with.creator != null)
stuff.creator = with.creator;
if (with.status != null)
stuff.status = with.status;
if (with.client_name != null)
stuff.client_name = with.client_name;
if (with.client_mail != null)
stuff.client_mail = with.client_mail;
if (with.client_phone != null)
stuff.client_phone = with.client_phone;
if (with.folder != null)
stuff.folder = with.folder;
if (with.flag1 != null)
stuff.flag1 = with.flag1;
if (with.flag2 != null)
stuff.flag2 = with.flag2;
if (with.flag3 != null)
stuff.flag4 = with.flag3;
if (with.flag4 != null)
stuff.flag4 = with.flag4;
if (with.flag5 != null)
stuff.flag5 = with.flag5;
if (with.flag6 != null)
stuff.flag6 = with.flag6;
if (with.flag7 != null)
stuff.flag7 = with.flag7;
}
Копирование данных из одного объекта в другой.
+1
namespace SmalltalkPHP
{
class Model
{
internal static void CreateClass(string className)
{
ClassObject = new Class(className);
}
public static Class ClassObject { get; set; }
public class Message
{
public class Arguments
{
private SortedList arguments = new SortedList();
public void Add(String key, String name)
{
this.arguments.Add(key, name);
}
public String AsPhp()
{
String[] sb = new String[arguments.Count];
int i = 0;
foreach (DictionaryEntry arg in arguments)
{
if ((String)(arg.Value) != "") sb[i] = "$" + arg.Value;
i++;
}
return String.Join(", ", sb);
}
public String MakeFunctionName()
{
String[] sb = new String[arguments.Count];
int i = 0;
foreach (DictionaryEntry arg in arguments)
{
if ((String)(arg.Key) != "") sb[i] = (String)arg.Key;
i++;
}
return String.Join("_", sb);
}
}
public class Generic
{
public virtual string AsPhp()
{
return "nya";
}
}
public class Unary : Generic
{
public Unary(String name, Boolean isStatic = false)
{
this.Name = name;
this.Arguments = new Arguments();
this.IsStatic = isStatic;
}
public string Name { get; set; }
public Arguments Arguments { get; set; }
public Boolean IsStatic { get; set; }
public string PhpHeader
{
get
{
return String.Format("public {0}function {1}()", IsStatic ? "static " : "", Name);
}
}
public override string AsPhp()
{
return PhpHeader;
}
}
public class Keyword : Generic
{
public Keyword(Boolean isStatic = false)
{
this.Arguments = new Arguments();
this.IsStatic = isStatic;
}
public string Name { get { return Arguments.MakeFunctionName(); } }
public Arguments Arguments { get; set; }
public Boolean IsStatic { get; set; }
public string PhpHeader
{
get
{
return String.Format("public {0}function {1}({2})", IsStatic ? "static " : "", Name, Arguments.AsPhp());
}
}
public override string AsPhp()
{
return PhpHeader;
}
}
}
}
}
Писал конвертер Smalltalk -> PHP
Где-то еще валяется Smalltalk -> Erlang