« first day (794 days earlier)      last day (4152 days later) » 

5:07 PM
Why do people do a switch .. case for 2 case statements?
 
@Zirak: rhetorical or serious question ?
 
cause its constant time
not that it matters since compilers will optimize it
 
If you have a serious answer, then it's a question. Otherwise, a rant.
@SimonSarris eh?
 
if you have
 
@Zirak: there is one, but I'm afraid you guys will kick my ass for that
 
5:09 PM
switch case 1: case 2: case 3: case 4:
 
technically spoken, switch/case is always faster than if/else. But we are talking really about overly microoptimization
 
In other words, no serious answer. My rant stands.
 
and in general I'd just say the ppl using a switch/case for 2 conditions are dumb
 
the serious answer is that the author has no faith in the compiler
 
It's written in a language which gets compiled to C, which then gets compiled again...
 
5:12 PM
in C# if/else that can be evaluated statically with a certain number of conditions are automatically compiled (ha) into a switch statement
most modern compilers should have that intelligence though
but hey
 
He also writes function calls like func (), so he should be flogged anyway.
 
maybe he just wants to be really sure a jump table will be used
 
yes, thats one reason why switch/case in general is faster. I don't know if current ecmascript implementations do optimize if-conditions into jmps
 
or maybe he's just optimistic that more switch cases will be added in the future
oh well if he writes func () then there's no hope for the guy
 
but also.. you should just optimize your conditions for yourself.. no sense in having 5 if else conditions if the last one gets most certainly called
 
5:14 PM
It's a directory reader...do you think there will more than types than file and directory?
 
depends is the author's name Reiser?
 
I wasn't talking specifically :p
 
maybe the author likes the clean deterministic feel of switch and 2 cases
 
proof of concept: jsperf.com/lol-vs-rofl
 
I can appreciate that
 
5:16 PM
:P :P
 
@jAndy having no real work done in the body of these may confound your results on jsperf
since js compilers try to be really really clever these days
 
firefox prefers the if-else case.. for... whatever crazy.. reason
 
cause it might only optimize that one
nay that just makes it worse!
firefox 25% slower on the switch
 
Firefox C++ implementation:

    if( strcmp( statement, "if( %s === 1 ) else if( %s ===2 )" == 0 ) {
        core.execute( statement );
    else {
        sleep( 200 );
        core.execute( statement );
    }
 
chrome nightly 15% faster
 
5:22 PM
wtf..
 
god, I love chrome
oh, chatbot has a santa hat
nice
@SOChatBot nice hat
 
why is IE10 so slow? jsperf.com/lol-vs-rofl/2
welp the results seem pretty different per browser
now I'm depressed
 
@SimonSarris You're really asking that?
 
I'm depressed because there are implementations where if-else is faster
makes no sense ? best case scenario it should be even performance
 
5349
A: Why is processing a sorted array faster than an unsorted array?

MysticialYou are the victim of branch prediction fail. What is Branch Prediction? Consider a railroad junction: Image by Mecanismo, from Wikimedia Commons: http://commons.wikimedia.org/wiki/File:Entroncamento_do_Transpraia.JPG Now for the sake of argument, suppose this is back in the 1800s - before...

 
5:26 PM
I mean......
 
@SomeKittens yes, IE10 has the best benchmarks in my canvas suite at the moment by a decent margin
12 seconds to run vs 15 seconds or so for the other browsers
 
what can be faster than.. jmp or jne instructions on assembly
which switch/case should directy get mapped to
 
@FlorianMargaine Apparently I already voted up that answer... I wonder how long ago that was.
 
Hey everybody, if you have a blog, can you link it for me?
 
on hiatus until book finishes :(:(:(:(
 
5:34 PM
ifIhadABlogItWouldNeverBeUpdated.net (.com was taken)
 
@RyanKinal margaine.com
french though.
 
And no RSS?
 
Florian, your blog's Frenchiness offends me.
 
lol
 
5:35 PM
but, up-to-date like ie6
 
I don't think I ever actually deleted my blog from my website... it only has one post though
 
Sweet! Thanks, everybody!
All of you that have RSS/Atom feeds have been added to my Google Reader
 
I'm not sure how I feel about this droidstack app... or why I'm using it
 
oh, if you have an RSS thingy we can add it to the room feeds
 
5:39 PM
boooooo
 
@FlorianMargaine: its a great anwer, but I honestly don't really get it. Why doesn't the cpu know ? I mean in his assembly, there is the cmp statement.. and then based on that there is the jmp statement
what need to guess is there ?
 
@KirstyHarris Boo?
 
@jAndy because it's faster when it guesses
 
realWorld.insertBefore( jAndy, rushHour ); // later folks, Florian answer! :p
 
i thought i would try scare you @ryankinal
 
5:45 PM
whats proper etiquette for taking over an open source project?
 
@KirstyHarris It didn't work
 
@Loktar Run in with guns blazing
 
theres this project I found that hasnt been maintained for 2 years
and has an error
do I fork it, or copy it and make my own repo all together?
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
damn
so.. its gnu 3 bleh I hate licenses
never know wtf I can and cant do
unless its mit
 
awww man!
 
Should I declare all vars at the start of a function, or if I'm doing additional processing at the end, can I declare the vars at the start of the additional?
Or is:
var sum, avg;
sum = times.reduce(function(a, b) { return a + b });
avg = sum / times.length;
overkill?
 
5:51 PM
@jAndy I like it! however I do not like how it rips down the original array. However that can easily be circumvented. I'll have to pickup that book.
 
You have a possible divide-by-zero error there, and if you're doing additional processing, shouldn't you pull that over to its own function?
 
bleh eff it
 
@Loktar o/
 
im going to just use what hes done as a nice stepping stone while rewriting it
hey @rlemon
 
TF2 makes me look like I've never played a FPS before in my life.
 
5:51 PM
oh shi!
Ill play tf2 with you man
I havent played that in a while
 
I just installed it last night - got owned in a few practice rounds.
never attempted real people
 
@SomeKittens I like the clarity of declaring all variables at the top of the function.
 
^ agreed
 
Another thing @SomeKittens! PS2 should have a sorta PvE mode. Going full blown PvP gives me the creeps.
 
variables at the top, functions at the bottom, business in the middle.
 
5:53 PM
ps2?
 
Planetside 2
 
ahh ok
I have that installed..
 
When I first loaded it up, I got out of that launching sequence thingy, and a tank killed me.
 
@Zirak That'd defeat the whole purpose
 
have yet to play it
 
5:53 PM
lol
 
@Loktar you should
 
I was "well now, wonder what do buttons do..." and a fucking tank fired at me
 
@Loktar I'm getting my gf into steam. I showed her the free to play and how to look up games and gave her my CC (told her she had a $100 limit) and she spend like 2 hours just browsing games and looking up trailers and shit
I'm still unsure which ones she picked yet.
 
bah, fuck you twitter. If you don't wanna give the ability to anonymously get shit, then maybe I won't use your API!?
 
looks pretty anon to me
I suppose I should link the newest API version docs.
 
5:56 PM
And it boggles the mind how for a 140 character message, they manage to attach so much default metadata
Just look at the example there, taking the first tweet: pastebin.com/56LKhsvN
3.22 kb, man. For a 140 character message.
And it's such a measly entry at that
 
@rlemon A $100 limit?
Hahaha
 
yea, fuck that.
i'm not buying her thousands of dollars worth of games
 
O_o
Learned something new today:   is not equal to the result of hitting the space bar
 
Yeah, you have to type a whole five extra characters
^attempting to be funny
 
Well, I was playing with Mocha and a new project
And tested whether DOM parsing worked as intended
Then I got surprised
 
6:09 PM
for(var j=0;j<5;j++) {
          //Get guess data
          guess = document.getElementById('input' + i).value;
          //Figure out b/w data
          bw = this.check(guess, toTest[x]);

          document.getElementById('black' + i).value = bw[0];
          document.getElementById('white' + i).value = bw[1];
          //Run results through nextStep
          nextStep(i);
          i++;
        }
^I cannot believe that A.) I wrote that and B.) it still works.
 
Is it a checkboard?
 
Nah, Mastermind
It's some test code. I need to refactor.
 
Why would you declare i globally? If it's a useful variable, give it a more descriptive name :p
 
deadlines...
fixing that now
 
@SomeKittens You fixed it! Good job :-)
 
6:18 PM
 
ok here is the demo for part one. jsfiddle.net/rlemon/ZWswQ
the blog post will outline how I got this far.
is that enough? then add images and shit on the next post, then proper UI on the third?
 
Good enough, yeah
 
You should read this: programmingpraxis.com
 
It'll be helpful too, since canvas doesn't have any real support for overflows for text
@RyanKinal Heyooo! amaanc.blogspot.com
 
well I was going to just do a post on text wrapping in Canvas. but because it ties so nicely into meme generation I would focus the first post on text wrapping, the second post on images, fonts, etc... and the third post on how to tie it all together to get a meme generator.
 
6:21 PM
@AmaanCheval Subscribed :-)
 
me! -------------------- ^
 
Also subscribed :-)
 
@rlemon Sounds good. Just make the title about text wrapping, not "Canvas Meme Generator Part 1" or something
 
... although, I unsubscribed from HN, because it was just too much
 
Yeah, same
 
6:23 PM
Canvas Meme Generator: Part 1 - Text Wrapping
 
@rlemon Yeah, good enough
Go go go!
 
lol
well I have the demo written! LOL
shouldn't that be good enough?
 
Ooh! Yeah! You should minify the code and post just that. No more :p
 
minify + obfuscate
 
Yeah, it'd suit your troll-self quite well!
 
6:26 PM
function generate() {
  var possible = [];
  //Generate all possibles
  //Lame and hacky?  Yes.  Gets the job done?  Also yes.
  for(var i=1000;i<=6000;i += 1000) {
    for(var j=100;j<=600;j += 100) {
      for(var k=10;k<=60;k += 10) {
        for(var l=1;l<=6;l += 1) {
          possible.push(i + j + k + l + '');
        }
      }
    }
  }
  return possible;
}
@SomeKittens o_O?
 
Got a better suggestion?
 
no, but looking at it makes me go o_O
4 levels of nested loops
:(
makes me sad
 
Yeah, same here
 
Sometimes there's no other way.
 
while (words.length > 0) {
    while (ctx.measureText(words[0]).width >= maxWidth) {
 
6:28 PM
However, that's nowhere near my record of 7: github.com/SomeKittens/Sudoku-Project/blob/master/…
 
^ from my text fragmenting code.
while in while... looks so vile.
 
@SomeKittens Haha, dude, what the heck?
Oh, Sudoku, okay, that may be justified
 
@SomeKittens :( :( :(
ok after this blog post I'm going through somekittens github just to refactor his code to not use 7 nested loops.
I won't sleep tonight otherwise.
 
lol
 
6:30 PM
Yo dawg, I heard you like while loops, so we put a while in a while so you can loop while you loop.
2
 
:)
 
while-ception
 
@OctavianDamiean in my case however, there really was no other option that was as performant.
5
Q: Splitting text into lines from a max width value for CANVAS

rlemonOk so this works as is, and is not actually slow at all (from what I can see) - However I don't like the taste of nested while loops and was wondering if anyone could give some insight on a different approach? Or how to improve mine to take away the while() { while() {}} Here it is: /* takes a...

I made sure of it.
 
I don't question that.
Done it myself once or twice, felt bad about it but that's in the nature of our cruel jobs.
 
the only thing wrong with this code is the use of 4 spaces and not 2
 
6:32 PM
You're wrong! :D
 
world erupts in flames
 
I prefer 4 spaces
Just because
 
@SimonSarris actually it used a tab, but the damn code formatters always convert them to 4 spaces.
 
THATS EVEN WORSE
 
1 byte vs 4?
YOU ARE EVEN WORSE!
 
6:33 PM
@rlemon It's in Java, which is why I haven't paid much attention to it
 
Four spaces all the way, my unicorn once told me it is the standard in unicornia so it must be good.
 
one tab all the way. it makes sense, is easier to type, easier to identify blocks, and easier to remove.
 
WTFPL should have a logo.
 
it does. the logo is whatever the fuck you want it to be.
 
@rlemon Yeah, I used to use tabs. Then I saw how ugly they are on Github
 
6:34 PM
@rlemon Right, it is also easier to fuck up certain text editors and textareas. :)
 
@OctavianDamiean so blame the TAB for other peoples ignorance about handling it?
 
Just had to change a setting in Sublime Text, and it's just as convenient now
 
Should I blame the ground for blowing up the plane when it crashes into it?
 
@rlemon Hmmm. Good point.
 
@rlemon You're getting the hang of how the world works now!
 
6:35 PM
@rlemon I didn't blame the TAB but since text editor implementations suck for it, better not use it.
At least that's my opinion.
 
my text editor handles it fine. online formatters (pretty print et al) do not.
VIM, notepad++, geany, VS all handle TAB vs SPACE perfectly.
anything else I don't care about.
 
Who's being ignorant now? :D
 
ST2 -> View -> Syntax -> Convert Tabs to Spaces // win
 
@OctavianDamiean ignorant online editors why assume the world uses spaces and not tabs. When clearly TAB is the logical choice (less bytes man! think of the bytes!)
 
> ST2 // win
 
6:37 PM
YEAH!
 
@RyanKinal Fixed that for you.
 
spaces === typography.
tabs === code formatting.
 
!!/todo add "Learn Sublime Text 2"
 
@OctavianDamiean Truth
 
@SomeKittens Y U NO MAEK SENSE!? Could not understand `todo add "Learn Sublime Text 2"`
@SomeKittens Item(s) added.
 
6:38 PM
@SomeKittens Learn?
There's not much to learn to get started
Just a lot of options to fiddle around with
 
There's still a learning curve, no matter what
Keyboard shortcuts, for one
 
I love the multiple cursors
 
!!s/Learn/Fuck Around With and Discover Cool Shit in/
 
@RyanKinal @SomeKittens Fuck Around With and Discover Cool Shit in? (source)
 
6:39 PM
@rlemon Indeed, bytes are getting more and more important iff we go back in time to the 80's.
 
I'm a tab man myself
 
@OctavianDamiean ok how about a single keystroke vs 4
 
nobody else in the shop shares my taste
 
@rlemon How about a good code editor? :)
 
@rlemon Insert tabs as spaces option?
 
6:39 PM
immediately I have 4 times the amount of productivity!
@RyanKinal seems like overkill to me.
why should my editor convert because some other developers prefer spaces.
let their editors do that for them. I prefer tabs
 
I have the same amount of productivity with 4 spaces, or 8, 16, 31, 64 or whatever.
 
@rlemon I hit the tab key for 4 spaces
Don't have to hit the spacebar 4 times
 
converting tabs to spaces is blasphemy
 
Actually, 64 spaces per TAB sounds like something I should try just for fun. :D
 
heretic
 
6:41 PM
meh, there is no right or wrong for tabs vs spaces. Pick one and stick with it for your entire project, aside from that any arguments for or against them are personal preferences and therefore are moot points.
 
/lash
 
@rlemon Agreed
 
@rlemon I've actually written a script that randomly inserts 2^n spaces, or an actual tab when I hit the tab key.
Makes for awesome spacing.
 
notices a girl enters the room..... runs to lean against the wall..... puts one foot up.... and crosses arms.... now I look cool
 
-_-
 
6:43 PM
posted on December 18, 2012 by Nicholas C. Zakas

Ever since I put together my Principles of Object-Oriented Programming in JavaScript class, I’ve been wanting to put together a resource that people who took the class could take home with them. I go through a lot of topics in the class and I didn’t think the slides would be enough to help people remember [...]

 
@rlemon Hahaha
 
@rlemon No sun glasses, mission failed.
 
@OctavianDamiean those are always on.
 
Oh, I see.
 
!!/choose "Make game" "Play game"
 
6:43 PM
I'm like horatio
 
@AmaanCheval Both!
 
Fuck you, man
 
@AmaanCheval Neither
 
Come on!
 
6:43 PM
hah
 
@AmaanCheval Make game
 
@AmaanCheval I swear i'm not controling it
 
Hahaha, I know
 
!!/tell Jet choose "Stay" "Go"
 
We totally believe.
 
6:44 PM
@Jet Go
 
@Gwendydd I upvoted your most recent question, in an hour or so you will be able to talk in here.
 
@rlemon You're sexist.
 
!!/tell Jet choose "lag" "lag"
 
@Jet Neither
 
Screw you!
 
6:44 PM
Hah, sucker
 
Hahaha
 
@AmaanCheval your train of though while deducing this was?
"userA: @userB I just upvoted you so you can chat in this room"
"userC: @userA, you are sexist!"
 
See? YOU ARE!
UserC agrees!
Sorry, I'm just bored
 
@AmaanCheval That's very unsexist of you
 
-1
Q: Car animations in Frogger on Javascript

Mijoro Nicolas RasoanaivoI have to finish a Frogger game in Javascript for my engineering school degree, but I don't know how to animate the cars. Right now I tried to manipulate the CSS, the DOM, I wrote a script with a setTimeout(), but none of them works.Can I have some help please? Here's my code and my CSS: <ht...

 
7:08 PM
folks
 
dudes
 
lol
 
@rlemon ^
 
1 message moved to recycle bin
 
7:10 PM
:D
 
never happened
 
hahaha the star is still there!
 
haha yeah
nice bug :p
 
7:10 PM
why is this not working when I do a click event..
 
@rlemon Of course, you can't delete the unicorn ... no one can.
 
Works fine in jsfiddle..not in the html!!
 
shux
 
1) you likely include your script files in the head. the fiddle is onload
2) try adding the code that fails to js fiddle. you mention click yet I see touchstart and mouseup
 
7:12 PM
I have no idea.. tried putting console.log but oh well
 
better way to do it jsfiddle.net/Gyxs6/2
 
yes, I have included my script files inside the head
 
I expected it to not have any jQuery @FlorianMargaine. Tsk tsk
 
@FlorianMargaine and @rlemon cool, I'll get on with debugging it!
 
@Andrew script files in the head that call DOM elements that load in the body.... think about it.
<head> I load first </head>
<body>
<element you want to touch on></element> <!-- I don't exist at the time your js is executed -->
</body>
so basically, you want to do two things. Wait for DOMContentLoaded or place your script files at the end of your body (I suggest placing your script files at the end of your body)
 
7:16 PM
@AmaanCheval okay... jsfiddle.net/Gyxs6/3
 
@rlemon good point sir.
 
Hehe, I like your mini-library
 
most elegant way I found
 
<html>
<head>
<title></title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<div class="content"></div>
<script src="app.js"></script> <!-- now all the HTML is parsed prior to the script being executed. Images and iFrame content is not guaranteed to be downloaded yet. -->
</body>
</html>
@Andrew look at this
 
woops, that won't work on FF3.5. Here you go: jsfiddle.net/Gyxs6/4
 
7:18 PM
wow my chat just lagged uber bad.
 
looking at it @rlemon
 
Who the hell still cares about FF3.5?
 
@rlemon DOMContentLoaded pretty please, you may get some flickering your way
 
That's worse than IE6 - because usually nobody forces FF3.5 on you
 
@rlemon yeah same
@ThiefMaster Matt McDonalds
 
7:18 PM
@FlorianMargaine meh, not really. JS shouldn't be manipulating your layout that much
load css in the head, js in the body after the content is parsed.
 
yeah, "shouldn't"
 
well I don't allow it too :P so i'm safe :P
 
meh
I'd like to work with you
maybe I'd end up saner
the current js code I see... oh well
 
I mean, it can and should manipulate based on user action. Not page load (IMO)
 
I don't wish anybody to see it.
@rlemon what about a very simple example: accordions?
 
7:20 PM
css :P
 
you fool
so js-disabled will never see your text
 
js-disabled can fuck off.
 
when I say js-disabled, I take google into account.
 
no, but seriously. This is an edge case.
 
because google will do worse: it will weaken the text
 
7:21 PM
I would have a "closed" class and allow js to apply that.
 
yeah, at DOMContentLoaded ;)
 
but regardless, these are edge cases that can be touched on a case by case basis
 
@SomeKittens Wow, that "petals of the rose" riddle was annoying
 
you end up with a lot of edge cases in most projects though
so yeah, I usually prefer to put it after the body
 
a general rule of thumb is don't allow js to touch your base layout. css is for that. put your js at the bottom of your HTML for perceived performance.
 
7:22 PM
but I often end up putting it in the head with a $(document).ready()
 
I don't like the head because it blocks while the js is being downloaded and parsed.
 
premature optimization :p
 
not really.
good practice
 
I was pretty disgruntled about the answer.
 
Which answer?
 
7:25 PM
3 mins ago, by Zirak
@SomeKittens Wow, that "petals of the rose" riddle was annoying
Took me a while but I had a lucky streak of similar dice-rolls, so I could work out the logic better.
 
7:54 PM
I didn't proof read it
someone wanna do that for me
 
Seriously? 11K retweets to that?
Okay, I'm going to bed
Bye!
 

« first day (794 days earlier)      last day (4152 days later) »