http://www.perlmonks.org?node_id=348478

Hi monks,

Usually I ask questions but here's something I would like to share with you...

I had to do a little javascript a couple of days ago and I found myself doing this:

To comment a line: # looping over an array to find the smallest number Instead of // looping over an array to find the smallest number
Of course the script didn't work and then I spotted the #. I was even doing this:
my var size = 0;
:)

Replies are listed 'Best First'.
Re: hangover from perl...
by exussum0 (Vicar) on Apr 27, 2004 at 14:50 UTC
    I have a good story for you. At least a funny one. I'm very multilingual in terms of programming languages. I know perl, c, some c++, java, etc...

    While at a php gig, I would use perl style comments. This isn't bad. php inherited perl's/shell's commenting style as well as c's. Anyway, I had a line I wnated to comment, and used the pound/number sign: #. Things worked fine.

    They pushed a release out with my new code, and everything started breaking left and right. Ugly sight. Eventually, the "CTO" of the company went out into production and looked at my code. "What is this?!" Pointing at my humble pound symbol. "It's a comment." A whole bruhaha was started about how comments are not allowed in production code and what not. First I had heard of the rule. THey traced it back to a process that would strip out comments and extra spaces, 'cause php would be "that much faster without extra characters"..

    Consequentally, out of 20 or so developers, none of them ever heard of using # symbols for comments in php. :\

      I have been a basic/foxpro programmer for several years and i do this in perl once in a while
      if ($var eq "hello") then ... ... ... }
      instead of
      if ($var eq "hello") { ... ... ... }

      You know, that seems more like a story about reasons not to work for that compony then a story about pitfalls of speaking too many languages.

      The CTO going into production? Not allowing comments in production? Production code being mangled, instead of being as close as possible to what was being tested? Using PHP?

      Avoid comments for speed? That's riddiculous. I've never yet heard of that. The usual claims are that comments are bad because you should write code such that it is clear without comments.

        php, like perl, in it's more bare form, skip the caching stuff or mod_perl, needs to compile scripts as they are called, no?

        With php at this company, the theory was (update not mine :P), less chars, the better for the parser. Don't ask me why and how valid the argument is for such a minute thing.

      Did you mention to them that using predefined constants is faster than using variables?

      ----
      : () { :|:& };:

      Note: All code is untested, unless otherwise stated

      perl, c, some c++, java
      Sorry, I don't think of that as "very multilingual".

      Reminds of the lame-o blog I saw a while ago. The dork said (something like) "I could be said to have a very broad taste in music. I like everything from rap, to hip-hop, to R&B..."

Re: hangover from perl...
by blue_cowdawg (Monsignor) on Apr 27, 2004 at 14:14 UTC

    I not only write code in Perl but in C, C++ and JavaScript and can so fully relate. Not as bad is when I write stuff in assembler. At least when I'm coding in assembler I go into "assembler mode" and don't mix so badly.

    Actually, back in the day when I was coding in both Z80 and MC6800x0 assembler I used to mix syntaxes. This normally occured during one of those all-night sessions we all know and love. When sleep deprivation takes over and caffiene just doesn't cut it any more.

    Many is the time when I am writing C code I have wanted to do string operations like:

    buffer1 .= buffer2;
    or
    buffer =~ s/\s+$//;
    or some other Perlism. Or this in Perl code:
    for(ix=0;ix<=5;ix++) { : :
    Where are the dollar signs?

    Can you spot the C code syntax errors here:

    for(ix=0;ix<=$#buffer;ix++){ $buffer[$ix]='\0'; }
    Just did that one last week at about 1AM.

      You could overload the $ and .= symbols.. :)
        Well, I don't know if you can override something that isn't an operator, but you can make macros and such :)

        Reminds me of the funny joke I saw once about C written in PASCAL:

        #define BEGIN { #define END }

        of course that can be made much more complex once our macros start taking parameters! :)

Re: hangover from perl...
by hardburn (Abbot) on Apr 27, 2004 at 14:03 UTC

    This is quite common for people who have to use more than one language at a time (at least, it is for me). The other day I was making a short C program and the compiler got mad at me for leaving the parens off function calls.

    ----
    : () { :|:& };:

    Note: All code is untested, unless otherwise stated

Re: hangover from perl...
by dragonchild (Archbishop) on Apr 27, 2004 at 14:12 UTC
    When I code, I have to have three separate modes:
    • My standard mode, which is Perl
    • My Javascript mode
    • My SQL or PL/SQL mode
  • They are completely separate and (mostly) unrelated. It's kinda like different hats at work. :-)

    /me ponders getting three hats in wildly differing colors, each with the appropriate language written on it.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

      dragonchild ponders getting three hats in wildly differing colors, each with the appropriate language written on it.

      Go for it, and post pictures! (And tell me where I can buy some!)





      My code doesn't have bugs, it just develops random features.

      Flame

Re: hangover from perl...
by Jenda (Abbot) on Apr 27, 2004 at 18:58 UTC

    The most common Perlism I do in other languages (VB, C#, JavaScript, SQL) is

    do_something if condition;
    I usualy do not finish this and write the condition where the language forces it to be, but I do start by the statement very often.

    Jenda
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
       -- Rick Osborne

    Edit by castaway: Closed small tag in signature

Re: hangover from perl...
by flyingmoose (Priest) on Apr 27, 2004 at 18:39 UTC
    I missed aliased foreach and map in java ... and a regex engine of better quality than the crappy one provided in 1.4

    I don't know when the last time I dollar-signed a variable erroneously, but I know I do things in C++ like try to use the . operator or use a post-statement conditional.

    I think the matter is compounded in languages of similar syntax, how everything is typically C-ish. I doubt I'd ever screw up Lisp or Brain**** for instance :)

Re: hangover from perl...
by CloneArmyCommander (Friar) on Apr 27, 2004 at 17:23 UTC
    Hahaha :). I find myself doing that a lot, but what I keep wanting to do is declare variables and arrays with $ and @ :). Luckily it hasn't done me any harm, yet :), since JavScript accepts it :).