Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Is the Java Compiler retarded?

Name: Anonymous 2009-10-27 3:15

Its telling me I need a return statement on the last line of my method even though that part can never be executed.. I am a novice at Java and I am teaching myself.. so is it just me that has bad coding style or is the java compiler a bit too OCD?

Name: Anonymous 2009-10-27 19:01

>>6

Here it is:

 public static String translate(String[] sourceLanguage, String[] destinationLanguage, String toBeTranslated){
    int i;

    //assume the word to be translated is not translatable,
    boolean isTranslatable = false;                  

    //check every word in the sourceLanguage array for that word.           
    for (i = 0; i < (sourceLanguage.length); i++){    
         //If it is there conclude that it can be translated and hence return it's equivalent
      if (toBeTranslated.equals(sourceLanguage[i])){ 
        isTranslatable = true;                        
        return (destinationLanguage[i]);                         
      }                                              
    }
    //if it still is not translatable, return "?????" to show confusion.
    if (isTranslatable == false){                    
      return ("?????");                              
    }
   
    return "This is dead code anyway";//the javac insisted on this..
  }

Name: Anonymous 2009-10-27 19:06





 public static String translate(String[] sourceLanguage, String[] destinationLanguage, String toBeTranslated){
    int i;

    //assume the word to be translated is not translatable,
    boolean isTranslatable = false;                  

    //check every word in the sourceLanguage array for that word.           
    for (i = 0; i < (sourceLanguage.length); i++){    
         //If it is there conclude that it can be translated and hence return it's equivalent
      if (toBeTranslated.equals(sourceLanguage[i])){ 
        isTranslatable = true;                        
        return (destinationLanguage[i]);                         
      }                                              
    }
    //if it still is not translatable, return "?????" to show confusion.
    if (isTranslatable == false){                    
      return ("?????");                              
    }
   
    return "This is dead code anyway";//the javac insisted on this..
  }

Name: Anonymous 2009-10-27 19:07

5/10

Name: Anonymous 2009-10-27 19:10

THIS IS ENTERPRISE QUALITY!

Non-ENTERPRISE way:

public static String translate(String[] sourceLanguage, String[] destinationLanguage, String toBeTranslated)
{   
    for (int i = 0; i < (sourceLanguage.length); i++)
    {   
        if (toBeTranslated.equals(sourceLanguage[i]))
            return (destinationLanguage[i]);                          
    }

    return ("?????");
}


Please don't post on /prog/ anymore (and remember to email all your posts to sage for the quickest answers!).  Thanks!

Name: Anonymous 2009-10-27 19:35

>>18
the fuck is up with the parentheses? how about return destinationLanguage[i]; and return "?????";

Name: Anonymous 2009-10-27 19:39

>>19
First, use sage when you are going to make a shitty post.

Second, >>15-chan likes parens around stuff such as his return values.  It helps him visualize the code, something someone like you would never understand.

Back to /reddit/, please!

Name: Anonymous 2009-10-27 20:15

>>16
How do I format my code here with syntax highlighting and fonts?

Name: Anonymous 2009-10-27 20:16

Okay, >>16-chan, so here are the ways in which your anus enjoys extracting every last drop of my cum with a delicate squeeze of its folds. First, you're checking whether isTranslatable has been set to false, even though it will always be false once that loop exits. This introduces your actual problem: The Javac is smart enouch to notice that you neglected to handle the else condition of your if statement, but not smart enough to notice that the if statement is itself completely redundant.

Second, you're combining two forms of program logic anyway! >>18-kun wrote a nice version that does what you want, but here's a version that separates the logic in a way you might understand bettar.

public static String translate(String[] sourceLanguage, String[] destinationLanguage, String toBeTranslated) {
    int i = lookup(toBeTranslated, sourceLanguage);
    if (i < 0) { // ...then the string is not in sourceLanguage.
        return "?????";
    } else {
        return destinationLanguage[i];
    }
}

public static int lookup(String whatever, String[] inAnArray) {
    for (int i = 0; i < inAnArray.length; i++) {
        if (w.equals(whatever)) {
            return i;
        } else {
            // do nothing, let the loop continue
        }
    }
   
    // Wasn't found
    return -1;
}

Name: Anonymous 2009-10-27 20:16

>>21
Use the [code] tag, you anus

Name: Anonymous 2009-10-27 20:20

>>16
Yeah um, your boolean flag is kindof useless there bub. It leaves scope immediately after you set it (since you return).

Yes, the last return statement is unreachable, but it's very difficult for a compiler to figure that out (impossible in the general case afaik, halting problem etc). Even a C/C++ compiler would warn about the equivalent code not returning.

You should just get rid of the flag (since it's useless) and do it like the non-enterprise anon above.

Name: Anonymous 2009-10-27 23:43

>>22
I had to submitted my own version because cheating is against my moral principles, but I will keep what you said in mind.

Name: Anonymous 2009-10-28 0:48

>>25
WHBT

Name: Anonymous 2009-10-28 0:54

>>25
Well then why the fuck did you ask. Sage it with fire.

Name: ​​​​​​​​​​ 2010-10-23 19:31

Name: Anonymous 2010-12-09 12:02

Name: Anonymous 2011-02-04 14:52

Name: 2013-01-25 18:17

搔䚑鑲㍦⒈怩砰牓疅遵ٲᤕ鈈፧ᖅ䀐嘃☂䦃劒圸䕇獂㆑占捷遈逷瞑гေህ蔡撅ᑢƇ焔顷•戠瑰䘷逸㄃၁薙閐銒晦摐敗蠑慘͸玈饥☰ᘦ⌥㑁မ膂ᠤ却ᜇኙ⑓㈡䕔ᔖܵ厖ؐ眲衉震䒙匹剹䥵ᤳ摠梗䢅聅遰圂䕖គ祹邕砀㕵坐眈愙⠗憐掐ࡴ睴蚂ឆ⦘爐焴儗饥ᦂᙣу喃ࡥ᥀硕艷    襧煥栢♰椠㦘䄘Ѥ蚙ॴ戗噧㚀莅剆㚆⒁悗頔鎖榈ᚇԆ䒕嘳ሇ怴瞆瘢ޅ䜈␧螒倇ဣ䀴✖熕袙℥㡳႔瘱昃挴阧栃䒘⒖畠܄䐥鄸䉄脖夃蔧㖃Ԕ╄呒垃坔㐉ᑠ㑧ᔔ⥡砂扅畴㄁焧撃᠙錹ʀ饒祁㕄镔䤴恒靧褉蕐䉀₈ᝢ甘肑葡癨ə襈瑕呂⑑䥨ፅ★挙錅ኖ嚑Д蕤ភԨ敔䄷匠蜗ࠆ㙃堡礧⤉聁垀䙙ㅦ☙垃捀ᝤ嘙琄疒朖㝗І蕳㙴艱琨鑃䕢䄄聹䔔鐅᜹㈒㡉䉢捧怑䕹⁔摤ሧᤐ䜇瀙產畕⥐ࢂ蝶र䠔聘鉱䢄⦑恁襗⤖䈴茂怸㢄茡匘舨睒指ሃ醀㍢焖㘉愵቉怖倄圱鞘桓覉琣酨邉坈䍄ࡖ㐸ђぷ牓怈䉖锣萐ᒈ蘣䥓ݩ墒當ងᙤ摐饸垗鍱攄摳ら瑢ㅑङմ⁧鍱愱靴⥑⚅࢑吤Đ␱卑椄ፄ坐舘䄦а␡ᥡ圐鄴ŷ㦈ㄔ抖む࢒ቀ䝱䉓⎔舁ކ蒉锇劈鑶З卑ᥨ⁅ဣ垂ᘩ馅㜴栦獃ㄷㄱ圈塗〡腈⢉ㅇ礱瀆夰咐͒劓匇ᑵ楄ᅡ睔ₐ癄厖Ř䒀᥷鉣䠆⥇眀ٰ醃牳㥩荣視腔㦄⎆衇挲䙰㒒怒ㅡ᥅☣㕒ၩ畡ᚔ⌐煩ᠶ褷餡猵ɷ霄ᐸ堄㜷吐連挴⡈㝱㒁㕔Ω䝲␨㜵㕕嘴ᙖ㈶ࢃ遑脥ၕゕↃ鍸䝂獕ᖙ␖顑獹逸圤扆襸镦⑧⊗ܡ傃╸ሡ酶蠷✧䑗联ޓŘ䡇充聶㤔

Name: Anonymous 2013-01-26 10:52

And this is still the best thread on /prog in like a week.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List