Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

HappyHippo posted:

But lazy evaluation...?

:doh:

Adbot
ADBOT LOVES YOU

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Internet Janitor posted:

If there's anything conducting interviews has taught me, it's that a shocking number of people with years of development experience on their resume have an extremely tenuous grasp of how to use loops in any language. Stuff like this is likely the product of trying random perturbations until the code seemed to be doing the right thing.

Amen brother.

Hughlander
May 11, 2005

leper khan posted:

lol computer engineering is circuit design and vhdl and stuff.

No that's Applied Physics (Actual Masters Degree my father has.)

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

Joda posted:

Even then, wouldn't splitting your vector up into multiple vectors be preferable? Linked lists are absolute murder on the dcache.

This is basically a deque, which is a common enough data structure to be in many standard libraries. Good locality in practice, appends are bounded in cost, random access and iteration have a bit more overhead than an array but are still pretty efficient.

Anyway, on the broader point, don't listen to SD. Formalizing the performance of an algorithm on a specific architecture would be a worthless exercise. Even if somehow it gave you a perfect cycle count, it would necessarily assume exclusive and uninterrupted use of all resources, and so you would still have to validate optimizations on a real machine+OS, just like you do today. It is important to remember that theoretical asymptotic improvements don't always map to real performance, but they certainly can, especially when they're implemented appropriately, i.e. with the same realistic understanding of locality, branch prediction, etc. that have been brought to bear on the asymptotically-worse algorithm.

raminasi
Jan 25, 2005

a last drink with no ice

Joda posted:

Even then, wouldn't splitting your vector up into multiple vectors be preferable? Linked lists are absolute murder on the dcache.

IIRC the thing was accessed like one time after creation, and this represented a tiny fraction of the program's running time, so just switching STL containers was a much better use of my time than rolling something fancy.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

HappyHippo posted:

But lazy evaluation...?

Actually, F# is an eagerly-evaluated functional lang, so that code is indeed doing a bunch of unnecessary checks. :eng101:

(Not that it matters for a compile-to-Javascript browser-based Pong, of course)

HardDiskD posted:

I can see that it looks like poo poo, and it might be wrong as well, but can you show a fixed version of this? I don't know functional languages. :shobon:

Personally, since the boolean vars are just a repetition of the possible outcomes, I would KISS and just use an if-else chain, with indentation to make it legible.

And as raminasi pointed out, a discriminated union that exists only to be the return type of a single function can be dropped by writing that function as an active pattern:

code:
let (|Top|Bottom|Left|Right|LeftPaddle|RightPaddle|NoCollision|) (leftPaddle, rightPaddle, ball) =

    if ball.element.y <= 0. 
        then Top

    elif ball.element.y + ball.element.height >= h
        then Bottom
    
    elif ball.element.x <= leftPaddle.x && 
         (not (ball.element.y >= leftPaddle.y && 
               ball.element.y <= leftPaddle.y + leftPaddle.height))
        then Left
    
    elif ball.element.x + ball.element.width >= rightPaddle.x + rightPaddle.width &&
         (not (ball.element.y >= rightPaddle.y && 
               ball.element.y <= rightPaddle.y + rightPaddle.height))
        then Right
    
    elif ball.element.x <= leftPaddle.x + leftPaddle.width && 
         ball.element.y >= leftPaddle.y && 
         ball.element.y <= leftPaddle.y + leftPaddle.height
        then LeftPaddle
    
    elif ball.element.x + ball.element.width >= rightPaddle.x && 
         ball.element.y >= rightPaddle.y && 
         ball.element.y <= rightPaddle.y + rightPaddle.height
        then RightPaddle

    else
        NoCollision

NihilCredo fucked around with this message at 21:53 on Dec 28, 2016

raminasi
Jan 25, 2005

a last drink with no ice
You could even do it with partial active patterns, which might be more readable in this case.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

raminasi posted:

You could even do it with partial active patterns, which might be more readable in this case.

Or with single-case active patterns, yeah.

But I think this way is cleaner, in part because you don't have to repeat the parameters over and over for each case definition, but mostly because having only one active pattern expresses the fact that all the collision types are mutually exclusive and comprehensive.

raminasi
Jan 25, 2005

a last drink with no ice
One of my peeves about F# is that your active pattern cases can be easily each split into their own function, or the compiler can confirm they're exhaustive, but never both.

Truga
May 4, 2014
Lipstick Apathy

hackbunny posted:

To top it off, font issues add that little bit of spice: Japanese fonts show the backslash character as a Yen sign. It works as a backslash in all aspects, except the user believes it's a Yen sign. I believe it's visually indistinguishable from the real Yen sign character, which must be fun to handle

Just read this very cool post, time to put my anecdote in: On the balkans, our backslash character was Đ or rarely even Ž until windows 2000 (I never figured out the pattern back then, same locale produced different results in different versions of microsoft OSes, but backslashes are finally \ with a balkan locale set since then). When I had to switch to Japanese windows, way back when, I wasn't even surprised by the yen sign. In fact, all the \ in your posts show as yen signs to me in firefox on windows. Yes, fixed width fonts that come with windows replace the backslash with a yen symbol if you switch to the japanese locale, and used to be changed to other random characters, I guess back when everyone still tried to cram all text symbols into 8 bits.

Now, here's the kicker. These characters seemingly don't have anything in common right? Backslash is just one character, one that's used as a fairly important thing, surely they could've ejected something less useful from ASCII (like one of those special snowflake picture characters nobody ever used anywhere) to make space in the codepage for local snowflake characters?

No. They actually do have something in common: they all sit on the same keyboard key. \, ¥ and Ž sit on the same key, depending on which layout I switch to. I think that's the logic behind the seemingly random path separator changes between locales.

Ok so that's one mistery solved. But what's with Đ and Ž in different DOS versions?. Well, Ž on my keyboard isn't where Đ is, but typing Ž into DOS or win9x prompt produces Đ in most versions. Ž, however, works correctly outside the command line. Yes, even on DOS. No, I don't know how, or why, or for what purpose.

Kazinsal
Dec 13, 2011
It's weird old DOS/Windows code page crap that stuck around in the Unicode era.

Part of the reason from my understanding for the weirdness is because the backslash didn't exist before the ASCII standard was developed, and its origin was for writing out full-height logical AND and logical OR operators for ALGOL.

More fun: forward slash has been a valid path separator since paths were introduced to DOS in 2.0. All the developers were UNIX guys, but backslashes were used as the default at IBM's insistence because CP/M and the CP/M-like tools used forward slashes for switches. You could pass paths with forward slashes to the DOS API and it'd be totally fine with it, but COMMAND.COM and the CP/M-like environment used forward slashes for switches and backslashes for path separators because everything had to feel like CP/M.

The UX developers for DOS 2.0 then snuck in a system call and a corresponding CONFIG.SYS flag called SWITCHAR that let you set the switch character used by the option parsing API to a dash instead of a slash.

xtal
Jan 9, 2011

by Fluffdaddy
https://github.com/facebooknuclide/atom-in-orbit

Now you can run your web app inside a desktop app inside a web app

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Now?

I've had a c9.io account for a few years now. Haven't done anything with it but use it for scratch space, but it's been pretty impressive for a while.

xtal
Jan 9, 2011

by Fluffdaddy

Munkeymon posted:

Now?

I've had a c9.io account for a few years now. Haven't done anything with it but use it for scratch space, but it's been pretty impressive for a while.

That's literally completely different

hobbesmaster
Jan 28, 2008

xtal posted:

https://github.com/facebooknuclide/atom-in-orbit

Now you can run your web app inside a desktop app inside a web app

I'm sorely disappointed that this wasn't referring to an intel atom SoC running on a cube sat.

necrotic
Aug 2, 2005
I owe my brother big time for this!

xtal posted:

That's literally completely different

Is it? c9 is an in-browser IDE and this aims to bring Atom into the browser, and their fs replacement doesn't hit the real filesystem from what I can tell.

Su-Su-Sudoko
Oct 25, 2007

what stands in the way becomes the way

necrotic posted:

Is it? c9 is an in-browser IDE and this aims to bring Atom into the browser, and their fs replacement doesn't hit the real filesystem from what I can tell.

c9 isn't a webapp desktopapp webapp, just a webapp

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



xtal posted:

That's literally completely different

The end goal is to have an IDE running in browser tab, but saving to the local filesystem (I think? the ~almighty cloud~ is mentioned, too) instead of a remote one. The other difference being that one is going through a compatibility shim to run on a more restrictive browser and one is purpose-built.

It's dumb because if you can't get to the web to just fuckin' download Electron, you can't get to this thing, either.

canis minor
May 4, 2011

http://nymag.com/selectall/2016/12/kid-gets-amazon-echo-dot-alexa-to-play-porn.html

quote:

Apparently, “play digger digger” is to a little redheaded kid what “No. 1 Funny Ringtones for Android Best New Annoying Comedy Parody Alerts Alarms Message Tones Tone Alert & Messages — Porn Detected! (Porno Ringtone Hot Chick Amateur Girl Calling Sexy gently caress oval office poo poo Sex Cock Pussy Anal Dildo Ringtones for Android” is to Alexa

TheresaJayne
Jul 1, 2011
OMFG i just found this. Now anyone in the industry knows one of the standard tests you are given for a job is convert Decimal to Roman Numerals, I just came across this painful code...

note that 99 = 90 (XC) + 9 (IX) XCIX rather than IC

code:

public static String intToRoman(int nbr) {

		// I'm still coming up with a smaller algorithm here && lower priority for now
		String retval = "";
		switch (nbr) {
		case 1:
			retval = "I";
			break;
		case 2:
			retval = "II";
			break;
		case 3:
			retval = "III";
			break;

missing out a lot....

		case 94:
			retval = "XCIV";
			break;
		case 95:
			retval = "XCV";
			break;
		case 96:
			retval = "XCVI";
			break;
		case 97:
			retval = "XCVII";
			break;
		case 98:
			retval = "XCVIII";
			break;
		case 99:
			retval = "XCIX";
			break;
		case 100:
			retval = "C";
			break;
		}
		return retval;
	}

Volguus
Mar 3, 2009
99 is XCIX in roman numerals since you're not supposed to have more than 2 levels of difference between letters. IC, while shorter, breaks that rule since you have 4 levels between I and C.

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"
XCIX is correct because you're not supposed to subtract a number from another that is more than ten times it.

The rest of it, though...

E:fb :(

Nuevo
May 23, 2006

:eyepop::shittypop::eyepop::shittypop::eyepop::shittypop::eyepop::shittypop::eyepop::shittypop::eyepop::shittypop::eyepop::shittypop::eyepop::shittypop:
Fun Shoe
I will never understand how things like this happen.

How do you (arguably) know how to write code, and not go "this is loving stupid, there has to be a better way" by the time you're at, like, case 8.

JawnV6
Jul 4, 2004

So hot ...

Nuevo posted:

I will never understand how things like this happen.

How do you (arguably) know how to write code, and not go "this is loving stupid, there has to be a better way" by the time you're at, like, case 8.

It's pretty easy. You start with the table for 1 to 100, CBA to figure out the 10x rule, and just transform the CSV table into the switch with s/// modifications.

Malcolm XML
Aug 8, 2009

I always knew it would end like this.
IIII, XXXX, CCCC etc are acceptable and there's no roman numeral standard~~~~~~~~~~~~

Vanadium
Jan 8, 2005

I sat down to write a Roman numeral thing once and looked up how to do it right and then added the first 20 numbers as unit tests and then I threw out all my code because I realized I just need the 20 first numbers and a lookup works just fine. :|

hobbesmaster
Jan 28, 2008

Nuevo posted:

I will never understand how things like this happen.

How do you (arguably) know how to write code, and not go "this is loving stupid, there has to be a better way" by the time you're at, like, case 8.

They should've just gone whole hog on the lut method and thrown that all into a global const char ** table.

Its how you do a ton of stuff on a weak microcontroller.

Weekend Bridges
Apr 8, 2015

by Smythe

Malcolm XML posted:

IIII, XXXX, CCCC etc are acceptable

Lisp even lets you pick:

code:
CL-USER 1 > (format nil "~@r" 444)
"CDXLIV"

CL-USER 2 > (format nil "~:@r" 444)
"CCCCXXXXIIII"

Westie
May 30, 2013



Baboon Simulator

A reminder for either myself or my colleague to post the snack overflow post of an incorrect arabic2roman numeral function which involved bitmasking

e: or was it this? http://stackoverflow.com/q/9073150

Westie fucked around with this message at 21:16 on Jan 1, 2017

xtal
Jan 9, 2011

by Fluffdaddy

Weekend Bridges posted:

Lisp even lets you pick:

code:
CL-USER 1 > (format nil "~@r" 444)
"CDXLIV"

CL-USER 2 > (format nil "~:@r" 444)
"CCCCXXXXIIII"

What the gently caress

canis minor
May 4, 2011

Westie posted:

A reminder for either myself or my colleague to post the snack overflow post of an incorrect arabic2roman numeral function which involved bitmasking

e: or was it this? http://stackoverflow.com/q/9073150

Yea, though I think it did pop up in this thread already.

As for content - http://stackoverflow.com/questions/21448544/converting-a-roman-numeral-to-integer/21452867

Absurd Alhazred
Mar 27, 2010

by Athanatos

Westie posted:

A reminder for either myself or my colleague to post the snack overflow

Best Typo of the Year. :allears:

hobbesmaster
Jan 28, 2008

Absurd Alhazred posted:

Best Typo of the Year. :allears:

yospos discusses Jeff Fatwood's Snack Overflow all the time

QuarkJets
Sep 8, 2008

JawnV6 posted:

It's pretty easy. You start with the table for 1 to 100, CBA to figure out the 10x rule, and just transform the CSV table into the switch with s/// modifications.

Yeah this would actually only take like a minute to code up, including the google search to get roman numerals 1-100. It's still bad but it probably didn't take long to write

uvar
Jul 25, 2011

Avoid breathing
radioactive dust.
College Slice
I wrote a program to find the longest way to express a positive integer as the sum of two Roman numbers, doing it in a 'clever' way. Then out of curiosity I tried to rewrite it in a functional language. The code was terrible, but I knew it, and it was a good learning experience.

It was a bit of a shame when I thought about it a few months later and realised there was a mistake in the clever part in both versions, spent a fraction of the original time writing a brute-force version to test it, and still got accurate results instantly.

IIRC, somewhat obviously in hindsight, the longest under 4000 is 3776 = MMDCCCLXXXVIII + DCCCLXXXVIII, swapping an M over for the equally-long alternative.

The Laplace Demon
Jul 23, 2009

"Oh dear! Oh dear! Heisenberg is a douche!"

xtal posted:

What the gently caress

Common Lisp's format as might as well be its own language:

Wikipedia posted:

code:
(let ((template "The lucky winners were:~#[ none~; ~S~; ~S and ~S~
           ~:;~@{~#[~; and~] ~S~^,~}~]."))
  (format nil template)
  ;; &#8658;   "The lucky winners were: none."
  (format nil template 'foo)
  ;; &#8658;   "The lucky winners were: FOO."
  (format nil template 'foo 'bar)
  ;; &#8658;   "The lucky winners were: FOO and BAR."
  (format nil template 'foo 'bar 'baz)
  ;; &#8658;   "The lucky winners were: FOO, BAR, and BAZ."
  (format nil template 'foo 'bar 'baz 'quux)
  ;; &#8658;   "The lucky winners were: FOO, BAR, BAZ, and QUUX."
  )

Coding wonder or horror? That's up to you.

raminasi
Jan 25, 2005

a last drink with no ice

The Laplace Demon posted:

Coding wonder or horror? That's up to you.

That's the Common Lisp motto, right?

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Malcolm XML posted:

IIII, XXXX, CCCC etc are acceptable and there's no roman numeral standard~~~~~~~~~~~~

Yeah, actual romans wrote numbers all sorts of ways and the rules people have made up for "roman numerals" don't really have any basis in reality.

LOOK I AM A TURTLE
May 22, 2003

"I'm actually a tortoise."
Grimey Drawer
More important than what the Romans did 2000 years ago is the fact that there's basically a de facto standard for Roman numerals now, which you should probably follow if you for some dumbass reason have to write code that outputs Roman numerals.

I guess I can see how a function that outputs Roman numerals could find some uses in the real world, but I'd love to see an example of production code in a non-toy app that has to take Roman numerals as input.

Adbot
ADBOT LOVES YOU

hyphz
Aug 5, 2003

Number 1 Nerd Tear Farmer 2022.

Keep it up, champ.

Also you're a skeleton warrior now. Kree.
Unlockable Ben

raminasi posted:

That's the Common Lisp motto, right?

(Defmacro wonder () (`,horror))

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply