There should be a "programmers license"...



  • @Captain said:

    Pager.js is truly trivial to use though.

    I was pleasantly surprise when I learned about extremely simple jQuery things like .animate and .load, and I'm a bit out of touch with current frameworking.


  • ♿ (Parody)

    @dhromed said:

    I only do inner spaces when there's too many parens in the condition.

    And don't you fucking dare to cuddle that else. You're not helping anyone.

    I liked this because I loath cuddling brackets. I always do inner spaces, because they're the opposite of a barrier to reading. Outer spaces look funny to me, though I can generally live with that on stuff like ifs and loops.


  • 🚽 Regular

    Aww, don't worry, little bracket. You're safe with me.

    *cuddles*



  • Perverted accoladophile.



  • @boomzilla said:

    Outer spaces look funny to me

    NospacesaroundifandforkeyworddslookslikethistomebutfunnilyIhavenotroublewhenit'sfunctionnames.


  • 🚽 Regular

    If you're talking about camelized function names, I suspect the differences in capitalization at the beginning of each word help.



  • No I'm talking about how if() and while() look dense and stupid, while functionName() looks perfectly fine.


  • 🚽 Regular

    Gotcha.


  • ♿ (Parody)

    Hmm...but it's just the parentheses that are there...the meat is separated by a space. Well, there's no accounting for taste, though this isn't a sticking point for me.



  • It seems that most of the mindshare is behind:

    • Bootstrap or Foundation for styling
    • jQuery for glue
    • AngularJS for MVVM

    I use Knockout for MVVM -- a choice I made before I became aware of AngularJS mindshare. I'm happy enough with it. Angular also seems to feature the typical Google bureaucratic API.

    MVVM is interesting. The idea is that MVC doesn't really capture how the web operates, at least for Ajax apps. A page itself has a model, which may or may not correspond to the database layer. An MVVM framework lets you express the "View Model" and bind it to the View. Typically, the framework observes whether values in the view model have changed or not.

    So, in the architecture I use, on an HTML request, I have the http handler return a page that is ready to accept data, using a "mapping" plugin (which turns an arbitrary JSON object into a view model). On a JSON request, I have the handler query the DB and construct the view model the front end is expecting. When the two come together, the MVVM framework binds the view model to the page, which populates it all.



  • The saga continues.

    From the same authors,
    ###I don't know the language I'm using

        public static byte[] padLeft(byte[] array, int size) {
            byte[] tmp= new byte[size];
            
            for (int index = array.length - 1; index >= 0; index--) {
                tmp[size---1] = array[index];
            }
            
            return tmp;
        }
    
        public static byte[] padRight(byte[] array, int size) {
            byte[] tmp= new byte[size];
            
            for (int i = 0; i < array.length; i++) {
                tmp[i] = array[i];
            }
            
            return tmp;
        }
    
        public static byte[] merge(byte[] head, byte[] tail) {
            byte[] tmp= new byte[head.length + tail.length];
            
            for (int i = 0, iHead = 0, iTail = 0; i < tmp.length; i++) {
                if (i < head.length) {
                    tmp[i] = head[iHead++];
                } else {
                    tmp[i] = tail[iTail++];
                }
            }
            
            return tmp;
        }
    

    Challenge: What would you do?

    Pick any of the above and tell me: what you would "improve" and how?



  • Rewrite in Haskell.

    Using truncation semantics:

    padLeft :: Int -> ByteString -> ByteString
    padLeft n bytes = let padding = take (n - (length bytes)) (replicate 0)
                       in take n $ padding <> bytes
    
    padRight :: Int -> ByteString -> ByteString
    padRight n bytes = take n $ bytes <> (replicate 0)
    
    merge = <>
    


  • I'm using Ember in my current project and like it a lot. Looked into Angular, didn't like all the data attributes. Also, POJO objects seemed like a performance bottleneck waiting to happen. But it seems to be gaining mindshare, so I might give it another go in the next project.

    Oh, and I'm 100% over the jquery spaghetti. From now on, it's MV* or nothing.



  • @dhromed said:

    No I'm talking about how if() and while() look dense and stupid, while functionName() looks perfectly fine.

    #define testCondition if
    #define repeatAsLongAs while
    


  • @presidentsdaughter said:

    for (int index = array.length - 1; index >= 0; index--) {
                tmp[size---1] = array[index];
            }

    I have a feeling this code was created with the sole purpose of telling people "hey, did you know there's a triple-minus operator"?



  • If that were JavaScript, most of the browsers' engines would barf on it.
    (I discovered this while using ImpactJS with Box2D, whose baking process included JSMin, and there were some bits in Box2D where it involved x - (--k) but without the parentheses, which condensed to x---k, which caused it to barf.


  • Discourse touched me in a no-no place

    I always liked the countdown arrow operator.

    public static byte[] padLeft(byte[] array, int size) {
        byte[] tmp= new byte[size--];
        for (int index = array.length; index --> 0 ;)
            tmp[size--] = array[index];
        return tmp;
    }
    

    But seriously, anyone not using System.arraycopy for this sort of thing in Java requires their head examining. [spoiler](It would be more interesting to see what the JITter makes of this code though; it's possible that it's just wasteful, not slow.)[/spoiler]


  • 🚽 Regular

    @dkf said:

    index-->0
    You can write it thusly, it will look better:

    index --> 0


  • Discourse touched me in a no-no place

    @Zecc said:

    You can write it thusly, it will look better:

    index --> 0

    And I have indeed done so. Good suggestion for ways to foncuse noobs.



  • @dkf said:

    But seriously, anyone using Java requires their head examining.

    FTFY


  • :belt_onion:

    I kind of like that formatting, reminds me of RPG



  • @presidentsdaughter said:

    software development should be a regulated and licensed profession, like advocacy, medicine, nursing

    So all the good, competent people can be forced to make WTFy code for those in power? (Not that that doesn't happen already, my point is it would happen MORE...and more expensively.)



  • @trithne said:

    Except that serial incompetence is demonstrably just as rife in already regulated and licensed professions.

    Someone beat me to it. :)



  • @dkf said:

    And I have indeed done so. Good suggestion for ways to foncuse noobs.

    Also, code is always improved by the use of the =+ err.. operator:
    for( int index =+ array.length; index --> 0; )

    Filed under: Nobody expects the unary plus.


  • BINNED



  • @Onyx said:

    Cross-posting since it's relevant:

    Hmm, not very familar with Javascript, so I had to google that. Is the |0 just to trip people up, or does it actually do something I'm missing (like a type conversion or so)?


  • BINNED

    From what I gather, it coerces a float to an int before bitwise OR-ing the number, effectively flooring it.

    Double bitwise NOT is to coerce it to a number in the first place. Kinda like using !! to coerce it to a bool.



  • I know a dev that used to do that but apparently stopped when he found that the JS files gzipped better when he used Math.floor instead. Thus the mandate was spoken, thus it was so.



  • Apparently the double ~~ already performs the floor(*) according to this.

    In my very quick, dirty and non-exhaustive tests, ~~x always results in the same as ~~x|0. (As does just x|0.)

    (*) "truncate" seems more accurate, since -1.5 => -1, rather than -2 as with Math.floor().

    Filed under: missing something


  • BINNED

    It's Javascript, who the hell knows? No, I don't feel like reading the specs.

    And yes, it sounds sensible that ~~ would do the job on it's own, but I buttumed it came from a source where more testing was done. I trust JS's buttumptions even less than my own, so I'll stick to parseInt / parseFloat and Math functions myself.


    Filed under: Unless you stick a string starting with 0 into an old JS parser and forget to define the base...



  • <insert cheesy joke about JavaScript not having a spec that you just know some pedantic dickweed will call out>


  • BINNED

    <insert reference to PHP>

    ... what?

    Oh fuck you Facebook, you ruined it all!



  • @Onyx said:

    <insert reference to PHP>

    ... what?

    Oh fuck you Facebook, you ruined it all!

    You know the next version is going to be PHP 7, right? But they're not planning to rid the language of the worst fuckery as far as I can tell 😦



  • Well, the original post didn't exactly explain what's going on, so I hoped somebody more versed in the javascripts could point out the cleverness (if there was any to be had).

    And, yeah, on the off-chance that I have write some javascript, I'll probably stick to Math & co too...


  • BINNED

    I don't even...

    Ok, how's this? If we're jumping to 7, how about you have 6 being just a supported version of the backwards compatible fuckery and give us something that doesn't make me pull out my hair as the next proper release?

    Am I making any sense here? Yes? Then it probably won't happen.



  • No, no, because 6 was going to be a thing that was Unicode-everywhere and it sort of died, which is why they're skipping to 7 to avoid the stigma of how badly 6 crashed and burned.



  • Nice one!

    I'm regularly using !!x to turn "truthy" values into true. But this one seems a bit too finicky. Both of them are pretty much the same thing - they rely on javascript cutting off decimals during bitwise operations. They will coerce numbers to 32-bit, so some precision could be lost. They will also coerce the negatives in the wrong direction, acting like Math.ceil() instead of Math.floor(). They are a bit faster, but unless I was flooring a lot of positive small numbers in a loop, I'd stick with Math.floor() in the real code.

    That said, here's a few more interesting tidbits:

    // Extract the integer from a one element array
    ~~[5]  === 5;
    ~~[-"6"] === -6;
    ~~[-"yo"] === 0;
    
    // Unfortunately, any other combination fails. ¯\_(ツ)_/¯
    ~~[5, 6] === 0
    
    // Also, how about this
    !~4 === !~"anything" === !~{} === !~[1] === false
    
    // So !~ turns everything to false.... except
    !~-1 === true
    
    // So, you can do
    console.log(!!~[1, 2, 3].indexOf(2) && "Has" || "Nope"); // > Has
    console.log(!!~[1, 2, 3].indexOf(4) && "Has" || "Nope"); // > Nope
    

    Yay javascript!



  • @Onyx said:

    I don't even...

    Ok, how's this? If we're jumping to 7, how about you have 6 being just a supported version of the backwards compatible fuckery and give us something that doesn't make me pull out my hair as the next proper release?

    Am I making any sense here? Yes? Then it probably won't happen.

    @Arantor said:

    No, no, because 6 was going to be a thing that was Unicode-everywhere and it sort of died, which is why they're skipping to 7 to avoid the stigma of how badly 6 crashed and burned.

    What about that new facebook thing? That could be the "PHP done right".



  • @cartman82 said:

    // So !~ turns everything to false.... except
    !~-1 === true

    Well, ~x is the same as (-x - 1), so...

    What the hell are they teaching kids in schools these days?



  • The point is, everything. Also how nicely it meshes with Array.indexOf().



  • You can just use ~index instead of !!(-index - 1). No need to overcomplicate things.



  • Hmm, a bit dirty. But true.


  • :belt_onion:

    @cartman82 said:

    Hmm, a bit dirty. But true.

    A dirty bit?

    And yes, doing the |0 does nothing... the bitwise OR with a 0 is just to throw off anyone that doesnt realize the | is a bitwise OR.

    TBH, I don't think I've seen the ~~ method used in the wild other than in obfuscation contests(which is where the |0 comes in) and js1k-style minifying contests.

    Edit - oh, and i think i saw it done in a graphic library's code where the speed boost of ~~ could actually be worthwhile



  • @darkmatter said:

    A dirty bit?

    Arrest that bit!!


  • :belt_onion:



  • @darkmatter said:

    A dirty bit?

    And yes, doing the |0 does nothing... the bitwise OR with a 0 is just to throw off anyone that doesnt realize the | is a bitwise OR.

    TBH, I don't think I've seen the ~~ method used in the wild other than in obfuscation contests(which is where the |0 comes in) and js1k-style minifying contests.

    Edit - oh, and i think i saw it done in a graphic library's code where the speed boost of ~~ could actually be worthwhile

    http://jsfiddle.net/0ew40hmu/

    They actually do the same thing twice.


  • :belt_onion:

    @ben_lubar said:

    They actually do the same thing twice.

    I suppose that is true - hadn't thought about the |0 doing the same coercion on its own as well. One coerces to int to flip the bits and flip them back, the other just coerces to int and does effectively nothing.

    I don't recall ever seeing the |0 method used as a stand-alone, but surely I must have seen it in the past to have remembered it the other day while trolling the other code topic.

    Either way, if you're using those to do Math.floor (or Math.ceil depending on the sign) there had better be a damn good reason, or else you're just being an asshole or a :trollface:



  • Well, there's no Math.truncate...


  • :belt_onion:

    @ben_lubar said:

    Well, there's no Math.truncate...

    But there is a parseInt()



  • Stumbled at this and immediately thought of this post...

    http://imgur.com/gallery/wR3ZxfB


Log in to reply