Warning: preg_grep(): Compilation failed: quantifier does not follow a repeatable item at offset 128 in /var/www/tg-me/post.php on line 75 Библиотека шарписта | C#, F#, .NET, ASP.NET | Telegram Webview: csharpproglib/5841 -
DRY (Don’t Repeat Yourself) — принцип, согласно которому каждый фрагмент знания должен существовать в системе только в одном месте. Никакого копипаста и дублирующей логики.
Проблема: дублирование валидации
// Пример плохого кода if (user.Age < 18) throw new Exception("User must be at least 18");
...
if (user.Age < 18) return BadRequest("User must be at least 18");
При изменении правила — нужно помнить обновить его везде. Ловушка копипаста.
Решение: вынос логики в общее правило
public static class ValidationRules { public static bool IsAdult(User user) => user.Age >= 18; }
Теперь в коде
if (!ValidationRules.IsAdult(user)) throw new Exception("User must be at least 18");
// И в другом месте: if (!ValidationRules.IsAdult(user)) return BadRequest("User must be at least 18");
Альтернатива: использование FluentValidation или DataAnnotations
public class User { [Range(18, int.MaxValue, ErrorMessage = "User must be at least 18")] public int Age { get; set; } }
Где чаще всего нарушают DRY в .NET:
• Повторяющиеся SQL-запросы и фильтры • Повторение одинаковых exception'ов, логов, сообщений • Дублирование конфигурации • UI-формы и компоненты
DRY (Don’t Repeat Yourself) — принцип, согласно которому каждый фрагмент знания должен существовать в системе только в одном месте. Никакого копипаста и дублирующей логики.
Проблема: дублирование валидации
// Пример плохого кода if (user.Age < 18) throw new Exception("User must be at least 18");
...
if (user.Age < 18) return BadRequest("User must be at least 18");
При изменении правила — нужно помнить обновить его везде. Ловушка копипаста.
Решение: вынос логики в общее правило
public static class ValidationRules { public static bool IsAdult(User user) => user.Age >= 18; }
Теперь в коде
if (!ValidationRules.IsAdult(user)) throw new Exception("User must be at least 18");
// И в другом месте: if (!ValidationRules.IsAdult(user)) return BadRequest("User must be at least 18");
Альтернатива: использование FluentValidation или DataAnnotations
public class User { [Range(18, int.MaxValue, ErrorMessage = "User must be at least 18")] public int Age { get; set; } }
Где чаще всего нарушают DRY в .NET:
• Повторяющиеся SQL-запросы и фильтры • Повторение одинаковых exception'ов, логов, сообщений • Дублирование конфигурации • UI-формы и компоненты
Bitcoin is built on a distributed digital record called a blockchain. As the name implies, blockchain is a linked body of data, made up of units called blocks that contain information about each and every transaction, including date and time, total value, buyer and seller, and a unique identifying code for each exchange. Entries are strung together in chronological order, creating a digital chain of blocks. “Once a block is added to the blockchain, it becomes accessible to anyone who wishes to view it, acting as a public ledger of cryptocurrency transactions,” says Stacey Harris, consultant for Pelicoin, a network of cryptocurrency ATMs. Blockchain is decentralized, which means it’s not controlled by any one organization. “It’s like a Google Doc that anyone can work on,” says Buchi Okoro, CEO and co-founder of African cryptocurrency exchange Quidax. “Nobody owns it, but anyone who has a link can contribute to it. And as different people update it, your copy also gets updated.”
What is Telegram?
Telegram’s stand out feature is its encryption scheme that keeps messages and media secure in transit. The scheme is known as MTProto and is based on 256-bit AES encryption, RSA encryption, and Diffie-Hellman key exchange. The result of this complicated and technical-sounding jargon? A messaging service that claims to keep your data safe.Why do we say claims? When dealing with security, you always want to leave room for scrutiny, and a few cryptography experts have criticized the system. Overall, any level of encryption is better than none, but a level of discretion should always be observed with any online connected system, even Telegram.