打字稿风格指南接口 [英] Typescript style guide for interfaces

查看:144
本文介绍了打字稿风格指南接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是可能没有一个唯一正确的答案,因为我不知道编码风格相当多样,尤其是不同的语言之间,在JavaScript VS在C#Pascal大小写方法,如骆驼的函数名称的问题。我很能接受。

this is a question that may not have a single correct answer, as I do realise coding styles are quite varied, especially between different languages, eg camel case function names in javascript vs pascal casing methods in C#. I can quite accept that.

也许我在担心这一点,但我刚开始寻找到打字稿,真的很喜欢它的外观并计划使用它Angular2一起,并希望建立一个良好的风格指南。

Maybe I am over worrying about this, but I am just starting to look into typescript, really like the looks of it and plan to use it along with Angular2, and want to establish a good style guide.

我真的不明白的是2点这里,不我使用的接口preFIX。在此之前,我认为这几乎是普遍现象。我有一类车,所以自然的名称,如果接口只是添加一个我在前面... ICAR。当你看到我preFIX你知道你有一个接口。

What I really don't get is point 2 here, not to use I prefix for interfaces. Until this, I thought that was almost universal. I have a class Car, so a natural name if the interface is just to add an I in front... ICar. As soon as you see the I prefix you know you have an interface.

我想跟进任何建议的做法,但是这一次我真的不知道该怎么走了。

I want to follow any suggested practice, but this one I really do not know which why to go.

无是否知道是什么原因,我认为是一个几乎普遍的惯例,正在这里气馁?我知道你可以使用任何你喜欢的约定,只是想知道是否有一些理由不以打字稿使用这个共同的约定。

Does none know why, what I thought was an almost universal convention, is being discouraged here? I know you can use whatever conventions you like, just wondering if there is some reason for this common convention not to be used in Typescript.

先谢谢您的任何意见/信息!

Thanks in advance for any opinions/info!

推荐答案

I 为preFIX是在一段时间Java和C#大(可能还包括其他)但我不认为这仍然被认为是一个好主意,但一个人如何可以改变的东西,是用来受到广大开发商和现有code基地。

I as prefix was big at some time for Java and C# (probably also others) but I don't think this is still considered a good idea but how can one change something that is used by the majority of developers and existing code base.

它类似于被普遍认为是不好的做法匈牙利命名法。只要给它一个有意义的名字。如果你有不同的的总比让通用接口和类FancyCar工具汽车更加自然。像prefixes事情只是prevent人们想什么他们真正想要的前preSS。另请参见 http://c2.com/cgi/wiki?IntentionRevealingNames

It's similar to hungarian notation which is universally considered bad practice. Just give it a meaningful name. If you have different kinds of Cars than make Car the universal interface and class FancyCar implements Car is much more natural. Things like prefixes just prevent people from thinking about what they really want to express. See also http://c2.com/cgi/wiki?IntentionRevealingNames

有也喜欢飞镖(可能很多人不知道),那里是没有的类这样一个明显的区别接口和语言。在DART可以实现任何类。在类的接口只是作为一个接口

There are also languages like Dart (probably many others I don't know) where there is not such a clear distinction between interface and class. In Dart you can implement any class. The class' interface just acts as an interface.

更新

我不说的命名很容易。事实上,我认为这是软件开发中最困难的部分之间的大部分或至少。这只是精英的一般consesus是技术原因,prefixes是不是最好的方法。这并不意味着有替代的仅具有优点和无缺点。这似乎在这种情况下命名如 UserService UserServiceImpl MockUserService 代替。这种方式在C最自然的方式你$ C $的大部分地区 UserService 的使用量和衍生物仅在prividers。否则,如上所述,一致性的方式更为重要。如果某些风格在您使用的语言更常见的,我建议你code使用这一点。

I don't say naming is easy. In fact I think it's the most or at least among the most difficult parts of software development. It's just that the general consesus of "the elite" is that prefixes for technical reasons are not the best approach. This doesn't mean there are alternative that have only advantages and no drawbacks. It seems in this case naming like UserService, UserServiceImpl, MockUserService is used instead. This way in most parts of your code the most natural way UserService is used and the derivates only in prividers. Otherwise, as mentioned above, consistency is way more important. If some style is more common in the language you use, I suggest to use this in your code as well.

这篇关于打字稿风格指南接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆