天道酬勤,学无止境

maintainability

Use Gradle function from other gradle file

I want to split my 300 lines build.gradle logically into multiple build files to make it easier to maintain and extend. As I've noticed, it is possible to split gradle tasks into multiple files and use them with: apply from: "myGradleFile" With this approach I sadly have no access to functions, defined in the second build script. Is it also possible to split Gradle functions into multiple files? Example: Let's say I have my default build.gradle with a Task which uses a function task doSomethingWithMyFunction { myFunction() } Now I have functions.gradle def myFunction(){ } So I want to access

2022-01-17 13:28:14    分类:问答    android-studio   gradle   maintainability

'from X import a' vs 'import X; Xa'('from X import a' versus 'import X; X.a')

问题 我已经看到一些 Python 程序员相当一致地使用以下样式(我们将其称为样式 1): import some_module # Use some_module.some_identifier in various places. 为了支持这种风格,您可以引用“显式优于隐式”的格言。 我见过其他程序员使用这种风格(风格 2): from some_module import some_identifier # Use some_identifier in various places. 我在样式 2 中看到的主要好处是可维护性——特别是对于鸭子类型的理想,我可能想将 some_module 交换为 some_other_module。 我也觉得风格 2 以“可读性计数”的格言赢得了分数。 尽管我倾向于不同意,但人们总是可以争辩说,在使用第一种样式时,搜索和替换也是一个不错的选择。 附录:注意到你可以使用as来解决样式 1 中从some_module到some_other_module的切换。我忘了提到决定在当前模块中实现some_identifier也很常见,这使得创建等效的some_module容器稍微有点尴尬的。 回答1 这两种情况都有用途,所以我认为这不是一个非此即彼的问题。 在以下情况下,我会考虑使用 from module import x,y,z :

2021-12-10 04:21:28    分类:技术分享    python   python-import   maintainability   duck-typing

在 C# 中简化覆盖 Equals()、GetHashCode() 以获得更好的可维护性(Simplify Overriding Equals(), GetHashCode() in C# for Better Maintainability)

问题 我发现自己经常重写Equals()和GetHashCode()以实现具有相同属性值的业务对象相等的语义。 这导致代码重复编写且维护起来很脆弱(添加了属性并且不更新一个/两个覆盖)。 代码最终看起来像这样(欢迎对实现提出意见): public override bool Equals(object obj) { if (object.ReferenceEquals(this, obj)) return true; MyDerived other = obj as MyDerived; if (other == null) return false; bool baseEquals = base.Equals((MyBase)other); return (baseEquals && this.MyIntProp == other.MyIntProp && this.MyStringProp == other.MyStringProp && this.MyCollectionProp.IsEquivalentTo(other.MyCollectionProp) && // See http://stackoverflow.com/a/9658866/141172 this.MyContainedClass.Equals(other.MyContainedClass)); }

2021-12-08 17:00:31    分类:技术分享    c#   equals   hashcode   maintainability

SQL 中常量的最佳模式?(Best pattern for Constants in SQL?)

问题 我见过几种用于“克服”SQL Server 中缺少常量的模式,但它们似乎都不能同时满足性能和可读性/可维护性问题。 在下面的例子中,假设我们的表上有一个完整的“状态”分类,选项似乎是: 只是对其进行硬编码,并且可能只是“评论”状态 -- StatusId 87 = Loaded SELECT ... FROM [Table] WHERE StatusId = 87; 使用状态查找表,然后加入该表,以便WHERE子句引用友好名称。 子查询: SELECT ... FROM [Table] WHERE StatusId = (SELECT StatusId FROM TableStatus WHERE StatusName = 'Loaded'); 或加入 SELECT ... FROM [Table] t INNER JOIN TableStatus ts On t.StatusId = ts.StatusId WHERE ts.StatusName = 'Loaded'; 定义了一堆标量 UDF,它们返回常量,即 CREATE Function LoadedStatus() RETURNS INT AS BEGIN RETURN 87 END; 进而 SELECT ... FROM [Table] WHERE StatusId = LoadedStatus(); (IMO

2021-11-30 01:45:17    分类:技术分享    sql-server   constants   maintainability

'from X import a' versus 'import X; X.a'

I've seen some Python programmers use the following style fairly consistently (we'll call it style 1): import some_module # Use some_module.some_identifier in various places. For support of this style, you can cite the "explicit is better than implicit" maxim. I've seen other programmers use this style (style 2): from some_module import some_identifier # Use some_identifier in various places. The primary benefit that I see in style 2 is maintainability -- especially with duck typing ideals I may want to swap some_module for some_other_module. I also feel style 2 wins points with the

2021-11-28 02:04:56    分类:问答    python   python-import   maintainability   duck-typing

代码管理:生成各种规则略有变化的源文件(code management: generate source files with slight variations of various rules)

问题 我有一个声明性语言(实际上是twolc )的源文件,我需要在其上编写许多变体:一个规范版本和许多非规范版本,每个版本都有一个或多个与规范不同的变体。 例如,假设规范文件具有三个规则: Rule A: Do something A-ish Rule B: Do something B-ish Rule C: Do something C-ish 那么一个变体可能具有与A和C的规范完全相同的规则,但B规则不同,我将其称为B-1 : Rule A: Do something A-ish Rule B-1: Do something B-ish, but with a flourish Rule C: Do something C-ish 想象一下,你在许多不同的规则上有许多不同的微妙变化,你有我的情况。 我担心的问题是代码的可维护性。 如果稍后我决定需要以某种方式重构Rule A ,那么我将有 50 多个文件需要手动编辑完全相同的规则。 我的想法是为每个规则设置单独的文件,并使用cat将它们连接成变体: cat A.twolc B.twolc C.twolc > norm.twolc , cat A.twolc B-1.twolc C.twolc > not-norm.twolc等 是否有任何旨在管理此类问题的工具? 有没有比我想到的更好的方法?

2021-11-22 17:47:48    分类:技术分享    makefile   maintainability   variations   code-maintainability

Best pattern for Constants in SQL?

I have seen several patterns used to 'overcome' the lack of constants in SQL Server, but none of them seem to satisfy both performance and readability / maintainability concerns. In the below example, assuming that we have an integral 'status' classification on our table, the options seem to be: Just to hard code it, and possibly just 'comment' the status -- StatusId 87 = Loaded SELECT ... FROM [Table] WHERE StatusId = 87; Using a lookup table for states, and then joining to this table so that the WHERE clause references the friendly name. SubQuery: SELECT ... FROM [Table] WHERE StatusId =

2021-11-19 07:18:40    分类:问答    sql-server   constants   maintainability

Simplify Overriding Equals(), GetHashCode() in C# for Better Maintainability

I find my self overriding Equals() and GetHashCode() frequently to implement the semantic that business objects with identical property values are equal. That leads to code that is repetitive to write and fragile to maintain (property gets added and one/both of the overrides are not updated). The code ends up looking something like this (comments on the implementation are welcome): public override bool Equals(object obj) { if (object.ReferenceEquals(this, obj)) return true; MyDerived other = obj as MyDerived; if (other == null) return false; bool baseEquals = base.Equals((MyBase)other); return

2021-11-18 16:00:05    分类:问答    c#   equals   hashcode   maintainability

概括工单(Generalizing work orders)

问题 你好,stackoverflowians, 我正在为工单设计表格。 问题: 有不同的工单模型(从现在开始称为WOM ) WOM 共享一些属性(数字、日期、描述等) WOM 具有以下详细信息: 工作完成的部门。 一些 WOM 使用储罐而不是扇区(产品在储罐中制备)。 产品及其数量(加上或没有有关产品的一些信息)适用于哪个部门。 在 WO 工作的人力资源。 工单上使用的材料 ... 等等 需要什么 工单的设计表和c的详细信息。 他们想知道资源是如何使用的。 设计查询以检索所有形状的信息。 约束 面向最终用户的简单演示。 概括工单模型。 做了什么 将所有工单及其详细信息设计为从工单编号作为母节点开始的层次结构。 WorkOrderTable (ID, ParentID, Type, Value) 工单示例 将分层数据转换为平面表 ID ParentID Type Value 38 0 Num 327 39 38 Sector 21 40 38 Sector 22 43 40 Product NS 44 40 Product MS 50 40 Temp RAS 48 44 Quantity 60 47 43 Quantity 25 41 39 Product ARF 42 39 Product BRF 49 39 Temp RAS 51 39 Cible Acarien A. 46

2021-11-12 20:05:41    分类:技术分享    sql   performance   database-design   maintainability

code management: generate source files with slight variations of various rules

I have a source file in a declarative language (twolc, actually) that I need to write many variations on: a normative version and many non-normative versions, each with one or more variations from the norm. For example, say the normative file has three rules: Rule A: Do something A-ish Rule B: Do something B-ish Rule C: Do something C-ish Then one variation might have the exact same rules as the norm for A and C, but a different rule for B, which I will call B-1: Rule A: Do something A-ish Rule B-1: Do something B-ish, but with a flourish Rule C: Do something C-ish Imagine that you have many

2021-11-12 14:59:35    分类:问答    makefile   maintainability   variations   code-maintainability