Check, check, testing, one, two



  • @ben_lubar said:

    That statement has side effects, so they needed to avoid using it if they didn't absolutely need to.

    It's funny because one of our projects compiles with zero errors and one warning. And since I don't touch it, I CBA to fix it.

    int i = 0;
    

    "Variable 'i' was declared but never referenced"



  • @darkmatter said:

    that word... I don't think it means what you think it means.

    Can we make "blakeyrantness" a word?



  • Awe = a feeling of reverential respect mixed with fear or wonder. That about sums it up.



  • So my question was aimed at figuring out if there was a reason why someone would do this based on the behavior of a different language.

    Any language in which the loop termination condition is not checked until after the first iteration needs such a pre-check. I haven't used COBOL for over 35 years so I'm unsure whether that applies (and ICBA to go and read a manual).



  • @Fjp said:

    Any language in which the loop termination condition is not checked until after the first iteration needs such a pre-check. I haven't used COBOL for over 35 years so I'm unsure whether that applies (and ICBA to go and read a manual).

    Interesting, that's in direct contrasts to what pretty much all modern languages do.



  • do{} while () is your friend.



  • @chubertdev - sorry you fail.... There is one very important difference between for and foreach that applies any time there is the possibility of something ese accessing the list (i.e. it is not a local scoped collection).

    ps: Everyone agrees the "if" was redundant.


  • BINNED

    @chubertdev said:

    Anyways, the question is based on the COBOL response in this thread:
    http://what.thedailywtf.com/t/how-not-to-use-a-switch-statement/1590/2/

    So my question was aimed at figuring out if there was a reason why someone would do this based on the behavior of a different language.

    There is a class of developers who pride themselves on learning only what is necessary to do their jobs, as opposed to wasting time learning all of the ins and outs of their tools and understanding at a deep level how things work. My guess is that you've encountered their handiwork.



  • @antiquarian said:

    There is a class of developers who pride themselves on learning only what is necessary to do their jobs

    Too bad there's no easy way to delete all instances of that class.


  • BINNED

    @HardwareGeek said:

    Too bad there's no easy way to delete all instances of that class.

    That's true, but I have a difficult way: Outlaw all programming languages except Haskell and Ada.

    Filed under: this should probably be in the Evil Ideas thread



  • @TheCPUWizard said:

    There is one very important difference between for and foreach that applies any time there is the possibility of something ese accessing the list (i.e. it is not a local scoped collection).

    You can't also modify the iteration variable in C#'s foreach, which means you can't do this:

    foreach (int x in xArray)
    {
      x = x + 1;
    }
    


  • @TheCPUWizard said:

    @chubertdev - sorry you fail.... There is one very important difference between for and foreach that applies any time there is the possibility of something ese accessing the list (i.e. it is not a local scoped collection).

    It's passed in by value, so scoped locally enough where there won't be anything affecting it.



  • @HardwareGeek said:

    Too bad there's no easy way to delete all instances of that class.

    That would be a Garbage Collector that people would pay a mint for.


  • :belt_onion:

    @Maciejasjmj said:

    foreach (int x in xArray)
    {
    x = x + 1;
    }

    I got bit by this one just yesterday, I wanted to alter the iterated string value to pass the same value through to 2 different functions without using another variable as an intermediate. It was like a 3-liner of a foreach, so I didn't care to do anything complex... Of course, I had to suck it up and use another variable :trollface:
    [code]
    foreach (string thing in xArray)
    {
    thing = String.Format("stuf{0}",thing.Replace("more","safd"));
    doOne(thing);
    doOther(thing);
    }
    [/code]
    instead became
    [code]
    foreach (string thing in xArray)
    {
    thing2 = String.Format("stuf{0}",thing.Replace("more","safd"));
    doOne(thing2);
    doOther(thing2);
    }
    [/code]

    because I REALLY didn't want to do this or I'd hate myself forever:
    [code]
    foreach (string thing in xArray)
    {
    doOne(String.Format("stuf{0}",thing.Replace("more","safd")));
    doOther(String.Format("stuf{0}",thing.Replace("more","safd")));
    }
    [/code]



  • @darkmatter said:

    I wanted to alter the iterated string value to pass the same value through to 2 different functions without using another variable as an intermediate.

    Like in a few other cases, VB.NET does that automatically behind the scenes for you:

    Dim xArray As Integer() = New Integer() {1,2,3}
    For Each x As Integer In xArray
    	x += 1
    	Console.WriteLine(x.ToString())
    Next
    

    Output:
    [code]2
    3
    4[/code]

    Another thing to note, the code highlighter that Dicsourse uses doesn't understand VB style comments (or doesn't support VB).



  • Not supporting VB sounds like a good idea to me. Next we should remove PHP highlighting as well.



  • Actually, according to the sample page of their syntax highlighter, VB.NET is supposed to be supported, but their method of trying to force it to use a specific language (defining the language after the three backticks, I swear they said that somewhere) doesn't work, it keeps wanting to auto-detect as PHP.

    VBScript does work that way, but doesn't have any syntax highlighting.

    Also, looked at @darkmatter's post before mine, and in that, the code highlighting assumed bash, not C#. The only other code block in this thread that was on "auto detect" seems to be thinking C# correctly.



  • @Arantor said:

    Not supporting VB sounds like a good idea to me. Next we should remove PHP highlighting as well.

    FTFY



  • Apparently you use vb after the first triple backtick to indicate VB. Oddly enough I discovered this by using teh el Goog monster and finding the result on another Discourse installation.

    @Maciejasjmj Baby steps, my friend, baby steps. A lot of the web is still PHP powered, so we have to tackle it piecemeal. First the highlighting. Then we take the WordPress monster down.



  • Dim x As Integer
    

    Doesn't work for me. Still tries using "auto detection" and shows it's thinking PHP.



  • Huh. I got no ideas then 😦



  • Looking on the highlightjs sample page, it supposedly suggested vbnet, which also didn't work, but right below that was vbscript, which did, but on here, the highlighting didn't match what was on their page.

    I'd wonder if Dicsourse is possibly using an old version of it, but they're using a minified version and no comment on the version number is otherwise visible.


    OK, They're using the default downloaded bundle for highlight.js, which doesn't include VB.NET and VBScript (and a bunch of other languages) by default.


  • Discourse touched me in a no-no place

    I assume from the fact it made it here that there's not an else?
    It wouldn't necessarily be the best... but if it did something else when record.ModifiedList.Length was <= 0 then it would make some sense.



  • Doesn't look horrible using triple-tick vb (not vbnet).



  • It's auto-detecting as PHP in that regard. It seems the highlight.js they're using doesn't support VB, and it's just matching and highlighting on PHP keywords.



  • Ahhh, yeah, you can tell on the Dim



  • VB is pretty dim.


  • Discourse touched me in a no-no place

    You should try using Clear Basic if you think VB is bad.



  • I had never heard of it prior to today. Thank you for inflicting that upon me.


  • Discourse touched me in a no-no place

    Happy to share the pain. A significant proportion of the time I spend doing development involves using that abomination.



  • I don't touch VB unless it's .NET

    Although, I don't mind going back and forth between that and C#, I'm comfortable in either.



  • @chubertdev said:

    I'm comfortable in either.

    As am I. I'm just not lucky enough for your first statement, though.


  • BINNED

    Ooh! How about Ch...

    Ch is a C/C++ interpreter and scripting language environment used by teachers, students, engineers and scientists around the world to learn math, numerical computing, C/C++, and write cross-platform code and embedded scripts quickly and efficiently. It is an alternative solution to C/C++ compiler.



  • List<T> is a REFERENCE type. It never gets "passed by value" in the sense of a C++ (or C) environment. The List inside the method is the same instance as outside the method, unless a new instance is explicitly created.



  • @TheCPUWizard said:

    List is a REFERENCE type. It never gets "passed by value" in the sense of a C++ (or C) environment. The List inside the method is the same instance as outside the method, unless a new instance is explicitly created.

    The list itself isn't being passed.



  • At least it's not Wasabi.



  • "record.ModifiedList" magically appears in the first line. One can not GUARANTEE that there is (nor can possibly ever be) another reference to "record" (such that list could be accessed), or the instance of the List<T> returned by the ModifiedList property. Unless one could be 100% certain that neither is true, changing "for" to "foreach" is a potentially breaking change.



  • I agree with that, my previous comments were in allusion to the code as it exists right now, in my company's code base.

    Ironically, the UpdateRecord(UserID, record.ModifiedList[i]); call simply passes a string value as the second argument, and UpdateRecord uses it (never modifies the value) to look in another place for the actual data to update..



  • Your codebase is TRWTF?



  • Can't that be said about most codebases?



  • All codebases are equally WTF, only some are more equal than others.



  • @Arantor said:

    Your codebase is TRWTF?

    It has a lot of WTFs. Mostly sane. Older stuff has some people who went psychotic and continued to code. Everything is a page as an app, just about. Mid-age stuff is half done by DBAs working both halves. New stuff is all super-web 2.0-ey AngularJS, with very little thought given to the server-side code. Plenty of .NET WTFs in there.



  • Not as bad as the Perl codebase, though:

       foreach $special_fieldname (@special_fieldnames){
    
          $cgiVar{$special_fieldname} =~ s/ *\n */\n/g;           #get rid of trailing spaces on lines
          $cgiVar{$special_fieldname} =~ s/\r//g; 
          while ($cgiVar{$special_fieldname} =~ m/<br>\n/){     #fix <br>
             $cgiVar{$special_fieldname} =~ s/<br>\n/\n/g;     
          }
          $cgiVar{$special_fieldname} =~ s/<br>/\n/g;
       
          while ($cgiVar{$special_fieldname} =~ m/\<p>\n/){      #fix <p>
             $cgiVar{$special_fieldname} =~ s/<p>\n/\n\n/g;     
          }
          $cgiVar{$special_fieldname} =~ s/<p>/\n\n/g;
    
          $cgiVar{$special_fieldname} =~ s/\n/<br>/g;           #replace all the \n with <br>
       }
    

    Why do I get the feeling that there's a module that would do this?


  • BINNED

    There probably is...

    Here's my clean up of that code however.
    Notes:

    1. the while loops are redundant when using /g.
    2. using the aliasing behavior of for to keep from typing $cgiVar{ $special_fieldname } everywhere.
    3. added /x to allow for clearer exposition and changed s/// to s{}{} to reduce backslashitis.
    foreach $special_fieldname (@special_fieldnames){
    
        for ( $cgiVar{ $special_fieldname } ){
    
          s{ \s*\n \s* }{ \n   }xg;        #get rid of trailing spaces on lines
          s{ \r        }{      }xg;        #remove \r
          s{ <br>\n    }{ \n   }xg;        #fix <br>
          s{ <p>\n     }{ \n\n }xg;        #fix <p>     
          s{ \n        }{ <br> }xg;        #replace all the \n with <br>
       }
    }
    



  • No, I just replaced it with one regex in Python. 😀


  • BINNED

    Yeah, I wasn't going to do more (collapsing into one regex) not after a couple snifters of brandy... That would have been interesting…



  • I once wrote a C interpreter in scheme. It was an - interesting - experience.



  • Please do not ask me how quickly that I can finish a handle of vodka.


  • Discourse touched me in a no-no place

    @ChaosTheEternal said:

    I'd wonder if Dicsourse is possibly using an old version of it, but they're using a minified version and no comment on the version number is otherwise visible.

    I'm not convinced they're using any recent version - though I could be looking in the wrong place here:

    [pjh@sofa discourse]$ find . | grep highlight | xargs grep --color hljs.registerLanguage | sed 's/hljs.registerLanguage("\([^"]*\)"/\n&/g'  | cat | cut -b-50 | sort
    ./public/javascripts/highlight.pack.js:var hljs=ne
    hljs.registerLanguage("apache",function(a){var b={
    hljs.registerLanguage("bash",function(b){var a={cN
    hljs.registerLanguage("coffeescript",function(c){v
    hljs.registerLanguage("cpp",function(a){var b={key
    hljs.registerLanguage("cs",function(b){var a="abst..."
    hljs.registerLanguage("css",function(a){var b="[a-..."
    hljs.registerLanguage("diff",function(a){return{al
    hljs.registerLanguage("go",function(a){var b={keyw
    hljs.registerLanguage("handlebars",function(b){var
    hljs.registerLanguage("http",function(a){return{i:
    hljs.registerLanguage("ini",function(a){return{cI:
    hljs.registerLanguage("java",function(b){var a="fa..."
    hljs.registerLanguage("javascript",function(a){ret
    hljs.registerLanguage("json",function(a){var e={li
    hljs.registerLanguage("makefile",function(a){var b
    hljs.registerLanguage("markdown",function(a){retur
    hljs.registerLanguage("nginx",function(c){var b={c
    hljs.registerLanguage("objectivec",function(a){var
    hljs.registerLanguage("perl",function(c){var d="ge..."
    hljs.registerLanguage("php",function(b){var e={cN:
    hljs.registerLanguage("python",function(a){var f={
    hljs.registerLanguage("ruby",function(f){var j="[a..."
    hljs.registerLanguage("sql",function(a){var b={cN:
    hljs.registerLanguage("xml",function(a){var c="[A-..."
    [pjh@sofa discourse]$ 
    


  • My edit after the line could've been more explicit. They are using either 8.0 or 8.1 (the latest), but... wait, hang on. They're using a custom download, because that script has Go and Handlebars, which aren't in the "most commonly used languages" list, so they had to include those specifically, but didn't include VB.NET or VBScript.


Log in to reply