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
Catalyst-proof
May 11, 2011

better waste some time with you

Internet Janitor posted:

For comparison, here's somebody else's C implementation based on the spec:
https://github.com/swetland/dcpu16/blob/master/dcpu.c

Am I allowed to think this is very elegant code?

Adbot
ADBOT LOVES YOU

mjau
Aug 8, 2008

Internet Janitor posted:

For comparison, here's somebody else's C implementation based on the spec:
https://github.com/swetland/dcpu16/blob/master/dcpu.c

That's not the same thing though. That screenshot from before was definitely a 6502 emulator (even the opcodes match), this dcpu thing is completely different. It's got different registers, all of which are 16-bit, opcodes and ops are different (has stuff like multiply and divide but missing other things), etc.

mjau fucked around with this message at 20:33 on Apr 4, 2012

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Threaded code? Pffft. Should be writing a jiter to get some actual performance or something, I mean I don't see any timing data or anything to indicate he's going the cycle-accurate route.

1337JiveTurkey
Feb 17, 2005

Jabor posted:

Threaded code? Pffft. Should be writing a jiter to get some actual performance or something, I mean I don't see any timing data or anything to indicate he's going the cycle-accurate route.

I think I remember someone that did an emulator which just translated the instructions to JVM opcodes but it seems like it'd be a bitch to actually split everything into procedures when developers historically could and did just screw with the stack.

tef
May 30, 2004

-> some l-system crap ->
welp a game designer writes terrible code

That Turkey Story
Mar 30, 2003

tef posted:

welp a game designer writes terrible code

I didn't know you were a game designer!

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."

mjau posted:

(has stuff like multiply and divide but missing other things)

My BCD arithmetic mode! :negative:

But yeah, I should've recognized the 6502 register set in his locals panel in that screenshot. Whoops.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

1337JiveTurkey posted:

I think I remember someone that did an emulator which just translated the instructions to JVM opcodes but it seems like it'd be a bitch to actually split everything into procedures when developers historically could and did just screw with the stack.

I doubt that ever could have worked. JVM performs validation on every branch to make sure that local types and stack lengths/types match up as well. You would have to out-clever the original developers by padding stacks and knowing when to pop.

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.

1337JiveTurkey posted:

I think I remember someone that did an emulator which just translated the instructions to JVM opcodes but it seems like it'd be a bitch to actually split everything into procedures when developers historically could and did just screw with the stack.

They didn't just screw with the stack, they also used lower-address portions of the stack space to do scratch calculations on the assumption that those memory locations were probably not holding valid stack data. Considering that things like the 6502 had a 256 byte stack that must have been tricky.

To sperg on about 6502 stuff: If you read through the ROM source code for the Apple II, you'll find comments where Wozniak divided his team into 'perverts', meaning software guys, and 'non-perverts' meaning hardware guys. He would lock off sections of the hardware interop code with comments like "Perverts may not pervert the following code for any reason" and then end the section with a comment "Perverts may pervert the following code for any purpose". Before there was Subversion, they used Perversion as source control.

Internet Janitor posted:

My BCD arithmetic mode! :negative:

The very concept behind BCD is a coding horror that belongs in this thread.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

PDP-1 posted:

The very concept behind BCD is a coding horror that belongs in this thread.

How so? A BCD encoding makes it far more efficient to format a number for display, at the cost of some additional complexity in performing arithmetic on it. It's the correct tradeoff to make in some situations.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

I like how almost every time someone posts a horror someone else knows why it's not a horror or not as horrible as it first seems.

I think it means there are no horrible programmers.

evensevenone
May 12, 2001
Glass is a solid.

mjau posted:

That's not the same thing though. That screenshot from before was definitely a 6502 emulator (even the opcodes match), this dcpu thing is completely different. It's got different registers, all of which are 16-bit, opcodes and ops are different (has stuff like multiply and divide but missing other things), etc.

the "DCPU" is the cpu you can program in his new game, which is apparently basically a 16-bit 6502 clone. So I think they are the same thing.

Senso
Nov 4, 2005

Always working
And now there's already a JS web-based version.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

evensevenone posted:

the "DCPU" is the cpu you can program in his new game, which is apparently basically a 16-bit 6502 clone. So I think they are the same thing.

In no way is this a 6502. Note that Notch originally wrote a 6502 emulator to see if that would be viable for his game (which is what's featured in the screenshot), but realized that the 6502 both provided a lot of functionality that he didn't want, and didn't provide functionality that he wanted.

1337JiveTurkey
Feb 17, 2005

Suspicious Dish posted:

I doubt that ever could have worked. JVM performs validation on every branch to make sure that local types and stack lengths/types match up as well. You would have to out-clever the original developers by padding stacks and knowing when to pop.

For very early systems I doubt that even if someone did get something working it'd be faster than interpretation due to all the edge cases that have to be tackled. Less limited systems seem more amenable because there's less pressure to take extreme measures for performance and some particularly troublesome options become impossible. For example self-modifying code in an architecture with a split cache and jumping into the middle of an instruction with a RISC instruction set.

I did find a project called JPSX which according to reports demonstrated full speed emulation of the Playstation using byte code translation with software graphics rendering to boot. There's a Google Code page for it with absolutely nothing though.

tef
May 30, 2004

-> some l-system crap ->
code:

from StringIO import StringIO
from httplib import HTTPResponse
class FakeSocket(StringIO):
    def makefile(self, *args, **kw):
        return self

def httpparse(fp):
    socket = FakeSocket(fp.read()+"\r\n")
    response = HTTPResponse(socket)
    response.begin()

    return response
:psyboom:

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Thermopyle posted:


I think it means there are no horrible programmers.

I think it means we're all horrible programmers.

Beef
Jul 26, 2004

Internet Janitor posted:

For comparison, here's somebody else's C implementation based on the spec:
https://github.com/swetland/dcpu16/blob/master/dcpu.c

Broken link, it can now be found on:
https://github.com/swetland/dcpu16/blob/master/emulator.c

Much nicer and probably faster than the notch botch.

edit: spoke too soon:

code:
if ((op & 0xF) == 0) {
		switch ((op >> 4) & 0x3F) {
		case 0x01:
			a = *dcpu_opr(d, op >> 10);
			if (d->skip) {
				d->skip = 0;
			} else {
				d->m[--(d->sp)] = d->pc;
				d->pc = a;
			}
			return;
		default:
			fprintf(stderr, "< ILLEGAL OPCODE >\n");
			exit(0);
		}
	}

Look Around You
Jan 19, 2009

Beef posted:

Broken link, it can now be found on:
https://github.com/swetland/dcpu16/blob/master/emulator.c

Much nicer and probably faster than the notch botch.

edit: spoke too soon:

code:
if ((op & 0xF) == 0) {
		switch ((op >> 4) & 0x3F) {
		case 0x01:
			a = *dcpu_opr(d, op >> 10);
			if (d->skip) {
				d->skip = 0;
			} else {
				d->m[--(d->sp)] = d->pc;
				d->pc = a;
			}
			return;
		default:
			fprintf(stderr, "< ILLEGAL OPCODE >\n");
			exit(0);
		}
	}

Maybe it's just me but that looks like it sticks to the semantics of the (fictional) ISA fairly well. That code is implementing the JSR instruction, and it's fairly readable I think. Using a switch statement for one case is odd, but other than that it doesn't look terrible for interpreting machine code. Actually, on thinking about it, the switch may be there for adding future "non-basic" instructions, as JSR is the only one specified right now.

Captain Capacitor
Jan 21, 2008

The code you say?

tef posted:

code:

from StringIO import StringIO
from httplib import HTTPResponse
class FakeSocket(StringIO):
    def makefile(self, *args, **kw):
        return self

def httpparse(fp):
    socket = FakeSocket(fp.read()+"\r\n")
    response = HTTPResponse(socket)
    response.begin()

    return response
:psyboom:

The only way this makes sense is if you need to mock up a third party's response during unit tests or something. At least that's the only way my brain will let me comprehend it.


VVVV Just read through httplib.py and now I see what you mean.

Captain Capacitor fucked around with this message at 19:20 on Apr 5, 2012

tef
May 30, 2004

-> some l-system crap ->
It's what happens when you try to parse http messages 'offline' from files. Nearly every parser is intertwined with socket code.

Captain Capacitor
Jan 21, 2008

The code you say?
There's always this if you can use it.

abiogenesis
Feb 4, 2009
code:
public <CT extends IC, DT extends ID<? super CT>> foo (ITT<CT> cClass, ITT<DT> dClass , List <? super DT> dList, List<? super aClass> otherDList)

This is government code.

This code is protecting your borders.

This is only one line of a 8000 line file containing similar methods :cry:

CGameProgrammer
Nov 5, 2008

baquerd posted:

Any of these are fine:

code:
if (thing) doStuff();

if (thing) {
  doStuff();
}

if (thing) 
{
  doStuff();
}

if (thing) { doStuff(); }
This is terrible:
code:
if (thing)
  doStuff();
I think a good compromise is:
code:
if (thing)
{ doStuff(); }

fishbacon
Nov 4, 2009
wonderful yet strange smell

CGameProgrammer posted:

I think a good compromise is:
code:
if (thing)
{ doStuff(); }
What about?
code:
if(thing)
{ 
   doStuff(
   ); 
}
Personally I like

code:
if (thing){ 
   doStuff(); 
}
best.

fishbacon fucked around with this message at 10:11 on Apr 6, 2012

tef
May 30, 2004

-> some l-system crap ->

Captain Capacitor posted:

There's always this if you can use it.

The raw object in requests points to the underlying urlib3 structures. Which in turn wrap httplib. Which has socket code entangled with the parser.

There are two parsers afaik that aren't intertwined with socket code

http-parser - contains a wrapper around nginx c code & a pure python parser

the pure python one doesn't seem to be rfc compliant or worse, reality compliant (specifically some servers send LF only and not CRLF, and a few get defate/gzip mixed up, head responses don't have a body but will have a content-length, and 204, 304 will not contain a body but can contain a length parameter)

and the http parser I ended up writing that has been battle worn with some terrible websites

edit: and sometimes you get crazy loving http messages - an earlier version of wget with warc support, decided to preserve the headers but unwrap the body, so you have to be able to skip specific headers when parsing.

tef fucked around with this message at 10:29 on Apr 6, 2012

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
PHP's == will convert arguments to floats if they look like numbers, even if both arguments are strings. That site has a lot of PHP WTFs, but this is the first time I've seen this one and I'm floored.

McGlockenshire
Dec 16, 2005

GOLLOCKS!
I see we're back to the PHP part of the spiral...

That WTF is actually worse than it looks at first glance. See, it's not silently converting the string to a float, it's converting the string to an integer, failing to do that because the number is too large to store as an integer, then converting it to a float.

csammis
Aug 26, 2003

Mental Institution
Hahaha, the PHP Sadness guy turned off commenting on his site. I guess too many people called out too many of his whines. I remember one where it was pretty clear he'd never understood what static meant.

e: to be clear about what I am saying: there is much to be sad about in PHP. This guy just couldn't be told that his complaints were themselves horrors.

shrughes
Oct 11, 2008

(call/cc call/cc)
http://www.codinghorror.com/blog/2012/04/speed-hashing.html

codinghorror posted:

Hashes are designed to be slow

codinghorror posted:

In reality the usable space is substantially less; you can start seeing significant collisions once you've filled half the space, but half of an impossibly large number is still impossibly large.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

I am struggling to understand why he describes checksums as being a way of assuring "uniqueness", or why he describes them as being like somebody's full name. The older article linked to in his second paragraph demonstrates that he does understand the purpose of a checksum, but the comparison to people's names seems fatuous.

het
Nov 14, 2002

A dark black past
is my most valued
possession

codinghorror posted:

If Moore's Law anticipates a doubling of computing power every 18 months, that's like peeking 10 years into the future. Pretty amazing stuff, isn't it?
Oh come on

Opinion Haver
Apr 9, 2007

It's funny because he has a good point at the end: use long passwords for yourself and use bcrypt or something for your password hashes. It's just cloaked in the usual Atwood bullshit.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
Jeff Atwood has been publicly struggling with passwords for several years, and with pontificating on subjects of which he has little understanding for his tenure as a blogger

Huragok
Sep 14, 2011

Otto Skorzeny posted:

Jeff Atwood has been publicly struggling with passwords for several years, and with pontificating on subjects of which he has little understanding for his tenure as a blogger

Dog barks, news at 11

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Het posted:

Oh come on

That doesn't seem too far off. I get 10.84 years using his numbers, so he's in the right ballpark.

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Hammerite posted:

That doesn't seem too far off. I get 10.84 years using his numbers, so he's in the right ballpark.

That would be along the lines of saying "between the ages of zero and nineteen, I never scored. But one time when I was twenty, my friend had sex (with a woman). That is infinitely more sex than I ever have had. My mom was wrong. This is the future."

tef
May 30, 2004

-> some l-system crap ->
Oh jeff :allears:

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

hieronymus posted:

That would be along the lines of saying "between the ages of zero and nineteen, I never scored. But one time when I was twenty, my friend had sex (with a woman). That is infinitely more sex than I ever have had. My mom was wrong. This is the future."

What? He's clearly giving an analogy to those who aren't familiar with the power of GPGPUs for this sort of processing: "this is how powerful your CPU will be in ten years"

Adbot
ADBOT LOVES YOU

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

Suspicious Dish posted:

What? He's clearly giving an analogy to those who aren't familiar with the power of GPGPUs for this sort of processing: "this is how powerful your CPU will be in ten years"

Incidentally, it isn't. The corollary (really a misinterpretation but whatever) of Moore's Law has been dead for years, and now Dennard scaling is gone too :(

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