0

This is not a technical but long lasting problem for me. For CSS codes, I used to put styles for DOM elements (class and id) in the order which is corresponding to their appearance sequence in the HTML codes.

The problem is that when the codes are getting longer and longer, it wastes (non-trivial) time for me to locate correct position to insert or modify a style.

The similar case happens to the JS codes also, in which I place functions in calling sequence.

The result is that I sometimes want to quickly write my thoughts down, and just append a style/function in the end of the css/js codes, and the sequence/ordering is interrupted which further increase the time that I search for code snippet.

I use Sublime Text mostly. And search function only helps if I know the keywords in css class or function name.

Is there any design or habit or tool to increase the efficiency for locating code segment in long source file?

4

1 回答 1

1

这篇博文最初是针对 CSS Hacks 的,但我想它也适用于你的情况。Harry Roberts 主张将 CSS hack 放在一个单独的文件中,这样你就可以更好地记住以后应该修复哪些 hacky 内容。或者找出谁搞砸了 CSS 或者它是如何做到的。

您可以使用一个shame.css 文件将快速更改放入(我这样做),一旦您对更改感到满意,您就可以将其放回您的组织结构中。

链接到博客文章

此外,还有一些 CSS Organizer 可用,例如Styleneat。这样你就可以到处写 css,然后通过管理器运行它(一旦你满意了),得到整洁的代码。

对于 javascript,您可以使用类似的 shade.css 策略,或使用 AMD(异步模块定义)工具(例如RequireJS )来组织您的 javascript 。

于 2013-09-06T02:41:30.263 回答