源代码中的类成员顺序 [英] Class member order in source code

查看:63
本文介绍了源代码中的类成员顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是问过的(问题308581) ,但是这个特定的问题和答案是C ++特有的,很多事情在Java或C#等语言中并没有真正的意义.

This has been asked before (question no. 308581), but that particular question and the answers are a bit C++ specific and a lot of things there are not really relevant in languages like Java or C#.

问题是,即使经过重构,我仍然发现我的源代码文件中有些混乱.我的意思是,功能体还不错,但是我对功能本身的排序方式不太满意.当然,在Visual Studio之类的IDE中,如果记住成员的调用方式,则找到成员相对容易,但这并非总是如此.

The thing is, that even after refactorization, I find that there is a bit of mess in my source code files. I mean, the function bodies are alright, but I'm not quite happy with the way the functions themselves are ordered. Of course, in an IDE like Visual Studio it is relatively easy to find a member if you remember how it is called, but this is not always the case.

我尝试了几种方法,例如将公共方法放在首位,但是这种方法的缺点是文件顶部的函数最终会在文件底部调用另一个私有函数,所以我最终一直在滚动.

I've tried a couple of approaches like putting public methods first but that the drawback of this approach is that a function at the top of the file ends up calling an other private function at the bottom of the file so I end up scrolling all the time.

另一种方法是尝试将相关方法组合在一起(也许按区域划分),但是显然有其局限性,好像同一类中有许多不相关方法一样,那么也许是时候将该类分解为两个或更多了较小的班级.

Another approach is to try to group related methods together (maybe into regions) but obviously this has its limits as if there are many non-related methods in the same class then maybe it's time to break up the class to two or more smaller classes.

因此请考虑以下问题:您的代码已正确重构,从而满足了代码完成中提到的所有要求,但是您仍然希望出于人机工程学的目的对方法进行重新排序>.您的处理方式是什么?

So consider this: your code has been refactored properly so that it satisfies all the requirements mentioned in Code Complete, but you would still like to reorder your methods for ergonomic purposes. What's your approach?

(实际上,虽然这不完全是一个技术问题,但这个问题确实使我烦恼不已,因此,如果有人能提出一种好的方法,我将不胜感激)

(Actually, while not exactly a technical problem, this is problem really annoys the hell out of me so I would be really grateful if someone could come up with a good approach)

推荐答案

实际上,我完全依赖我的IDE的导航功能,即Visual Studio.大多数时候,我使用F12跳转到声明(或使用Shift-F12查找所有引用),然后使用Ctrl +-跳回.

Actually I totally rely on the navigation functionality of my IDE, i.e. Visual Studio. Most of the time I use F12 to jump to the declaration (or Shift-F12 to find all references) and the Ctrl+- to jump back.

之所以如此,是因为大部分时间我都在编写自己没有编写的代码,并且我不想花时间重新排序方法和字段.

The reason for that is that most of the time I am working on code that I haven't written myself and I don't want to spend my time re-ordering methods and fields.

PS:我还使用 RockScroll ,它是VS加载项导航和滚动大文件非常容易

P.S.: And I also use RockScroll, a VS add-in which makes navigating and scrolling large files quite easy

这篇关于源代码中的类成员顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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