Mistři v programování na #hovnokod

Jak snadno spočítat polovinu něčeho.

    /// <summary>
    /// Class for extensions.
    /// </summary>
    public static class Extensions
    {
        /// <summary>
        /// Count the half value.
        /// </summary>
        /// <param name="valueToBeHalved">Value to be halved.</param>
        /// <returns>Returns half value</returns>
        public static double Halved(this double valueToBeHalved)
        {
            double halfCoefficient = 0.5;
            return valueToBeHalved * halfCoefficient;
        }
    }

Anonymous,

je to jasne???

var fromId = lastId;
var nextId = fromId;
do
{
   fromId = nextId;
   ...
}(nextId != fromId);

Anonymous,

štýl ala "Kapitán Andrej Danko"

public IEnumerable<PermissionGroupDto> Get()
        {
            var companyPermissionGroups = _ctx.CompanyPermissionGroups.Where(g => g.CompanyId == _user.CompanyId);
            return _ctx.PermissionGroups
                            .Include(g => g.Permissions)
                            .Join(
                                companyPermissionGroups,
                                c => c.Id,
                                t => t.PermissionGroupId,
                                (c, t) => _mapper.Map<PermissionGroupDto>(c)
                            );
        }

Anonymous,

Čitateľný kód nie je priorita...

        private void RemoveItemPrices(ItemDto itemDto, Item dbItem)
        {
            for (int i = dbItem.ItemPrices.Count - 1; i >= 0; i--)
            {
                var item = dbItem.ItemPrices[i];
                if (!itemDto.ItemPrices.Select(p => p.Id).Contains(item.Id))
                {
                    _ctx.ItemPrices.Remove(item);
                    dbItem.ItemPrices.Remove(item);
                }
            }
        }

Anonymous,

ako napisat while...

public override void Process(ICommandInputData inputData, bool sendAsap = false)
        {
            _commandsBuffer.Add(new CommandPack{ InputData = inputData, SendAsap = sendAsap });

            ProcessCommands();
        }

        private void ProcessCommands()
        {
            if (_processing == false)
            {
                _processing = true;

                while (true)
                {
                    if (_commandsBuffer.Count > 0)
                    {
                        List<CommandPack> commandsBuffer = _commandsBuffer;
                        _commandsBuffer = new List<CommandPack>();

                        foreach (CommandPack data in commandsBuffer)
                        {
                            ProcessCommand(data);
                        }

                        continue;
                    }

                    break;
                }

                _processing = false;
            }
        }

Anonymous,