Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I just saw a demonstration of Zen Coding. I think it's a great investment on productivity, however my work is 99% backend data processing via Java.

So far I only know templates in Eclipse like sysout and foreach (then hit CTRL+SPACE in MS).

Is there more Zen Coding for Java?

share|improve this question
    
you can add templates to eclipse, though it can be a pain for some non trivial stuff –  ratchet freak Jun 11 '13 at 19:36
    
@JonBecher Please don't use backticks for emphasis, they are only meant for inline code. –  Yannis Rizos Jun 11 '13 at 20:04
add comment

1 Answer

I may be wrong, but "Zen Coding" is meant to be more useful for languages where you have a high level of nested elements in a structure (LISP, anyone?!).

As a simple case of HTML, you may have an example as follows:

<div id="page">
    <div class="logo"></div>
    <ul id="navigation">
            <li><a href=""></a></li>
            <li><a href=""></a></li>
            <li><a href=""></a></li>
            <li><a href=""></a></li>
            <li><a href=""></a></li>
    </ul>

Using the concept of Zen Coding, this can be shortened to something as follows:

div#page>div.logo+ul#navigation>li*5>a

This allows you to type much less code, but have it automatically expand your string of text into an editable code block, so that you don't need to go through the process of additional brackets, tags, etc., in order to get the expected output.

In the case of Java, for example, your code should be much less nested, and more "flat", using classes, methods, etc., in order to achieve the same result. Example, if you have a block of Java code that looks like this:

public static void main() {
    private int x = 1;
    while (x < 10) {
        if (x < 5) {
            for (int i = 0; i < 100; i++) {
                switch(i) {
                    case 1:  //Do Stuff here
                    case 2:  //Do more stuff
                    default: //Do more complex nested stuff here
                }
            }
        }
        x++;
    }
}

You should look at restructuring the above code into a much more managable, less nested block of code, rather than trying to shorten up the typing of the code by attempting to do some shorthand like:

public/static/void/main>while(x<10)>if(X<5)>for(new(i[0..100]))>switch[1/2/Default]
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.