Coding: Fleeting Thoughts

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

User avatar
Shivahn
Posts: 2200
Joined: Tue Jan 06, 2009 6:17 am UTC

Re: Coding: Fleeting Thoughts

Postby Shivahn » Fri May 25, 2012 2:39 am UTC

EvanED wrote:Really, most instructions operate on word level, not byte level, so base 4 billion-whatever for a 32-bit machine (or one in 32-bit mode, like x86). I'm pretty sure your typical RISC architecture (thinking of MIPS specifically) doesn't even have a way of operating on individual bytes, except for the lb and sb instructions.

Heh, my knowledge is pretty out of date on that level. I actually did consider register size when thinking about this, but ended up just going with bytes because they're the lowest addressable thing.
Ben-oni wrote:I think saying computers "think in 1's and 0's" is fair, actually. That's the smallest unit that the computer can operate on. For instance, when you program, you can access each individual bit in a file. You can't get at any finer representation, like the actual electric potential state.

If you are lucky enough to work with a language that has good bitstream processing capabilities, then as the programmer you actually can deal with individual bits. And why not? It doesn't matter that the actual representation might not be bytes (in signal processing, you often deal with symbols that can attain a number of states that is not a power of two), but by the time it reaches the processor, it's bits.
Well, I can deal with the bits directly in C++ too. My main reason for saying that computers "think" in higher bases is because I can't ask the computer for a bit, I have to ask it for a byte and then have it process it to give me the bit. That can be abstracted, but at the most basic level, it's getting its atomic representation of data and then altering it to give me a piece of it, rather than just grabbing that piece. It can't do anything to that piece without doing stuff to seven others, so... yeah.

Though there are clearly more subtleties than I originally thought of, so I'll have to consider them.

Also,
EvanED wrote:Computers think in voltages. :-)

Psh, people have been doing that since they existed :P

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Coding: Fleeting Thoughts

Postby EvanED » Fri May 25, 2012 2:49 am UTC

Shivahn wrote:I...ended up just going with bytes because they're the lowest addressable thing.

Even that's not always true... on many architectures, load addresses have to be word-aligned, and if they're not you'll get a bus error. (Often there's a load-unaligned pseudoinstruction, but that just does two aligned loads and puts them together with bit twiddling.)

In fact, if the request goes all the way to main memory, it may has to be aligned at the size of an L2 or L3 cache block, which may also be the minimum transfer size -- and that's quite large, apparently 256 bytes on the Core i7. (It's possible my guess is wrong here though.)

User avatar
Shivahn
Posts: 2200
Joined: Tue Jan 06, 2009 6:17 am UTC

Re: Coding: Fleeting Thoughts

Postby Shivahn » Fri May 25, 2012 2:51 am UTC

Oh wow, that's interesting! I need to read up on computer architecture, apparently.

Ben-oni
Posts: 278
Joined: Mon Sep 26, 2011 4:56 am UTC

Re: Coding: Fleeting Thoughts

Postby Ben-oni » Fri May 25, 2012 5:27 am UTC

Shivahn wrote:it's getting its atomic representation of data and then altering it to give me a piece of it

Then it's not atomic after all, is it? After all, "atomic" means it can't be broken down any more, no matter what you do to it. In Information Theory, the bit is the smallest unit of information possible. That's the atomic structure.

User avatar
Shivahn
Posts: 2200
Joined: Tue Jan 06, 2009 6:17 am UTC

Re: Coding: Fleeting Thoughts

Postby Shivahn » Fri May 25, 2012 9:32 pm UTC

Atomic was probably the wrong word. You are strictly right, but it's sort of like subatomic particles to chemists - only really important in that they influence the atomic properties of a thing.

I may have veered pretty far into that metaphor.

Ben-oni
Posts: 278
Joined: Mon Sep 26, 2011 4:56 am UTC

Re: Coding: Fleeting Thoughts

Postby Ben-oni » Fri May 25, 2012 9:57 pm UTC

I blame chemists for this mess of language. They jumped the gun when they named the "atom". So when physicists discovered fission, we ended up in a right mess.

User avatar
PM 2Ring
Posts: 3700
Joined: Mon Jan 26, 2009 3:19 pm UTC
Location: Sydney, Australia

Re: Coding: Fleeting Thoughts

Postby PM 2Ring » Sat May 26, 2012 1:42 am UTC

EvanED wrote:Really, most instructions operate on word level, not byte level, so base 4 billion-whatever for a 32-bit machine (or one in 32-bit mode, like x86).


Word up! :)

EvanED wrote:Even that's not always true... on many architectures, load addresses have to be word-aligned, and if they're not you'll get a bus error.


I haven't done much assembly programming in recent years, but I used to dabble in it occasionally on my Amiga. The Motorola MC68000 chip definitely did not like unaligned accesses and programs that attempted such things would crash the machine; this could be quite painful to newbie assembler programmers when doing byte-level accesses, eg in simple string processing. The higher members of the MC68k family could recover more gracefully from alignment errors, but the recovery process was rather slow, so it was always desirable to organize one's code to avoid all alignment errors in the first place. IIRC, even on x86 family chips unaligned accesses are much slower than properly aligned ones.

User avatar
Sc4Freak
Posts: 673
Joined: Thu Jul 12, 2007 4:50 am UTC
Location: Redmond, Washington

Re: Coding: Fleeting Thoughts

Postby Sc4Freak » Sat May 26, 2012 2:05 am UTC

I think x86 is basically the only architecture that allows unaligned memory access.

moiraemachy
Posts: 190
Joined: Wed Jan 04, 2012 9:47 pm UTC

Re: Coding: Fleeting Thoughts

Postby moiraemachy » Sun May 27, 2012 8:02 pm UTC

Word size is a fuzzy concept in CISC architectures, in which there generally are byte-oriented instructions that can be faster than word-oriented ones because they don't require some sort of unpacking, and many sorts of extended registers. And it's a complete mess in x86 due to backward compatibility, and intel kind of defining word as 16 bits.

I guess the biggest reason to say that computers think in bits is the way the instructions are implemented physically: with logic gates that can be modeled as receiving and sending binary values. So it'd be more accurate to say that computer designers think in bits.

I like to say that computers "think" in tests and jumps, since that's how behavior that seems complex is implemented.

User avatar
The Great Hippo
Swans ARE SHARP
Posts: 7357
Joined: Fri Dec 14, 2007 4:43 am UTC
Location: behind you

Re: Coding: Fleeting Thoughts

Postby The Great Hippo » Mon May 28, 2012 10:59 am UTC

I realized today as I'm learning more about Python that you not only can treat functions as objects, you can save them (with Python's pickle routine) and reload them, allowing you to call functions without ever even naming them (just assign them to a variable with the pickle function!). However, if you remove the function from code, you get an error (basically, 'AttributeError, module object has no attribute 'print_this''). I'm wondering if there's a way to overcome this (I think there is, and I think the solution is the code in Ben-oni's example back in my Python newbie thread). I find it to be a really interesting facet of Python if it's possible, although its use is dubious (how useful is it to have a bunch of functions in your code that will never be defined anywhere--existing purely as objects you've loaded from a savefile?).

I also realized just today that Python's ducktype nature means I can create a module wth dummy classes with the same attributes and functions as my normal classes (albeit empty ones--just 'pass' for the functions, just empty values for the attributes) and refer to them in the normal functions, save those normal functions, load them into my main module, and the relationship should still persist. In other words, if it's possible to load functions without ever explicitly declaring them into a python module, I could theoretically replace all my functions with functions I loaded from a pickled file.

Which strikes me as really, really weird, and really, really cool (albeit really, really pointless).

User avatar
Aaeriele
Posts: 2127
Joined: Tue Feb 23, 2010 3:30 am UTC
Location: San Francisco, CA

Re: Coding: Fleeting Thoughts

Postby Aaeriele » Mon May 28, 2012 5:46 pm UTC

The Great Hippo wrote:I realized today as I'm learning more about Python that you not only can treat functions as objects, you can save them (with Python's pickle routine) and reload them, allowing you to call functions without ever even naming them (just assign them to a variable with the pickle function!). However, if you remove the function from code, you get an error (basically, 'AttributeError, module object has no attribute 'print_this''). I'm wondering if there's a way to overcome this (I think there is, and I think the solution is the code in Ben-oni's example back in my Python newbie thread). I find it to be a really interesting facet of Python if it's possible, although its use is dubious (how useful is it to have a bunch of functions in your code that will never be defined anywhere--existing purely as objects you've loaded from a savefile?).


I'd try to avoid getting into the habit of pickling objects, and especially functions. It will eventually get you in trouble. It's best to only store actual data on disk and not code.

Also, as far as calling functions without ever having named them...

Code: Select all

(lambda foo: __import__("sys").stdout.write(foo))("Hello, world!\n")


There's a one-line hello world program that calls a function without ever actually naming it.
Vaniver wrote:Harvard is a hedge fund that runs the most prestigious dating agency in the world, and incidentally employs famous scientists to do research.

afuzzyduck wrote:ITS MEANT TO BE FLUTTERSHY BUT I JUST SEE AAERIELE! CURSE YOU FORA!

User avatar
The Great Hippo
Swans ARE SHARP
Posts: 7357
Joined: Fri Dec 14, 2007 4:43 am UTC
Location: behind you

Re: Coding: Fleeting Thoughts

Postby The Great Hippo » Mon May 28, 2012 6:16 pm UTC

Oh yeah, it's definitely not something I'm planning on ever really doing--I just thought it was a really weird and potentially fun consequence of being able to store functions in objects (and then pickle said objects).

User avatar
Xeio
Friends, Faidites, Countrymen
Posts: 5101
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\
Contact:

Re: Coding: Fleeting Thoughts

Postby Xeio » Mon May 28, 2012 6:28 pm UTC

Phhht, that's boring, you should load up a list of strings, then load the functions defined in them and run them! Way more dangerous fun.

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Mon May 28, 2012 9:11 pm UTC

Got cold called (or rather, mailed) by a google recruiter. I feel flattered.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
Yakk
Poster with most posts but no title.
Posts: 11115
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Tue May 29, 2012 1:17 am UTC

Those guys are just mercs who get paid if you get a job at google after they "recruit" you.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

jareds
Posts: 436
Joined: Wed Jan 03, 2007 3:56 pm UTC

Re: Coding: Fleeting Thoughts

Postby jareds » Tue May 29, 2012 2:59 am UTC

That describes almost all recruiting. I would assume, however, that Google is a competent enough organization that the recruiters wouldn't be tolerated unless they're sufficiently selective to improve the quality of the candidate pool versus not using recruiters.

So, yeah, obviously he shouldn't think he's being actively targeted like he's Brian Kernighan, Ted Ts'o, etc.; but I'm not inclined to believe that they're super-spammy about it either.

User avatar
Aaeriele
Posts: 2127
Joined: Tue Feb 23, 2010 3:30 am UTC
Location: San Francisco, CA

Re: Coding: Fleeting Thoughts

Postby Aaeriele » Tue May 29, 2012 7:42 am UTC

Aaeriele wrote:
Steax wrote:I'd have moved to other frameworks if only getting good hosting for them were easy. For small-ish websites that can't afford/don't need a virtual/dedicated server, I've still yet to find a good one.


Heroku is one reasonable option. Their free tier works fine for "small-ish" websites.


Someone just mentioned Webfaction today, which apparently will also host Django, Rails, etc with more of a shared hosting-esque pricing scheme.
Vaniver wrote:Harvard is a hedge fund that runs the most prestigious dating agency in the world, and incidentally employs famous scientists to do research.

afuzzyduck wrote:ITS MEANT TO BE FLUTTERSHY BUT I JUST SEE AAERIELE! CURSE YOU FORA!

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Tue May 29, 2012 3:54 pm UTC

jareds wrote:That describes almost all recruiting. I would assume, however, that Google is a competent enough organization that the recruiters wouldn't be tolerated unless they're sufficiently selective to improve the quality of the candidate pool versus not using recruiters.

So, yeah, obviously he shouldn't think he's being actively targeted like he's Brian Kernighan, Ted Ts'o, etc.; but I'm not inclined to believe that they're super-spammy about it either.


They probably do this because of Impostor Syndrome and Dunning-Kruger. A lot of qualified people are going to consider themselves not having a chance, while a lot of people who actively apply are complete hacks with no chance of getting hired.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
Steax
SecondTalon's Goon Squad
Posts: 3038
Joined: Sat Jan 12, 2008 12:18 pm UTC

Re: Coding: Fleeting Thoughts

Postby Steax » Wed May 30, 2012 1:23 am UTC

Aaeriele wrote:
Aaeriele wrote:
Steax wrote:I'd have moved to other frameworks if only getting good hosting for them were easy. For small-ish websites that can't afford/don't need a virtual/dedicated server, I've still yet to find a good one.


Heroku is one reasonable option. Their free tier works fine for "small-ish" websites.


Someone just mentioned Webfaction today, which apparently will also host Django, Rails, etc with more of a shared hosting-esque pricing scheme.


These guys look interesting, and seem to be more of what I'd expect a typical host to be. I'll check them out, thanks!
In Minecraft, I use the username Rirez.

User avatar
Shivahn
Posts: 2200
Joined: Tue Jan 06, 2009 6:17 am UTC

Re: Coding: Fleeting Thoughts

Postby Shivahn » Thu May 31, 2012 12:17 am UTC

This is sort of a broad question of the fleeting-thought type, so this seems like a good place for it.

What are some good programming tools? I mean, ok, there are good compilers. And a text editor I can configure to do what I want is important (I'm using SciTE now, I fucked my libraries up so I can't use the Code::Blocks IDE anyway.) An IDE combines a lot of these, but I'm getting by fine with SciTE, valgrind, gdb, makefiles and g++.

But I'm talking about more broad stuff. Like, for example, I recently thought to myself "Man, this program is getting... complex. I know I've abstracted things mostly correctly, but I want an easy way to visualize how everything fits together." I managed to query Google in a way that lead me to Doxygen and Graphviz, which I'm gonna use when I get home, but it made me realize that I don't just not have useful tools, I don't even know what tools are useful.

Basically, I don't just lack the knowledge of which tools are useful, I lack the metaknowledge to begin to explore this area.

So that said, does anyone have any suggestions, either of tools, or of broad programming primers that have lists of useful tools: not basic stuff like debuggers, but like graph visualizers and whatnot? I feel like I might be having a harder time than I need to, because I don't know more in terms of tools than what is needed.

User avatar
Steax
SecondTalon's Goon Squad
Posts: 3038
Joined: Sat Jan 12, 2008 12:18 pm UTC

Re: Coding: Fleeting Thoughts

Postby Steax » Thu May 31, 2012 12:37 am UTC

What languages and areas are you working in?

Related to doxygen: I previously didn't subscribe to the complex comment school of thought. You know, these things:

Code: Select all

/**
 * Attempt to login, and register through fAuthorization when successful.
 * 
 * @throws fNotFoundException        When no user by provided username exists
 * @throws sfBadPasswordException    When the given password fails to match
 * 
 * @param string $username             Username for attempted login
 * @param string $password             Provided password to match
 * @return boolean                     True when successful
 */
public function login($username, $password)
{
}
 


But after the last few months of implementing them, they've turned to be really useful. My current workflow now is to set class structures in these blocks, and then fill in each function as necessary. It only takes a few moments to write and help me visualize the program quite well. And then doxygen converts that to nice documentation that other people can use.

(Before this, I usually just went for the minimum commenting style, hoping my code would explain itself. I still use it for small projects - I use extensive commenting on libraries and other large chunks of code.)
In Minecraft, I use the username Rirez.

User avatar
Shivahn
Posts: 2200
Joined: Tue Jan 06, 2009 6:17 am UTC

Re: Coding: Fleeting Thoughts

Postby Shivahn » Thu May 31, 2012 12:49 am UTC

Well, right now I'm writing a component-entity system for a 2D game idea I have. It's a bit of an ongoing project that is honestly probably never going to get finished. Though I'm finally at the point where if I wanted to I could start adding content rather than framework (for example, I could turn the current framework into pong in about ten minutes). It's in C++.

I really meant rather broadly though - I know it's a broad question, so broad as to be possibly useless, but even just knowing terms like "graph visualization" and other keywords that describe concepts that might be useful would help.

(Also, my commenting probably needs work. It's pretty minimalist right now: I need to make sure I'll get it in three months)

User avatar
sourmìlk
If I can't complain, can I at least express my fear?
Posts: 6393
Joined: Mon Dec 22, 2008 10:53 pm UTC
Location: permanently in the wrong
Contact:

Re: Coding: Fleeting Thoughts

Postby sourmìlk » Thu May 31, 2012 2:54 am UTC

Apparently I can write retrocausal code, so long as I compile it on MinGW O.o

Also, variadic templates are cool. In an entity-component system, it is useful to be able to grab all entities that have certain kinds of components. So I have a getEntityByComponentTypes() function that takes (n > 0) template arguments. The returned list of entities will only return entities containing all of the types specified in the template parameters. And I get to do it with recursion, which is often fun. I get why people like functional programming. I also get why people hate it.
Terry Pratchett wrote:The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it.

User avatar
Steax
SecondTalon's Goon Squad
Posts: 3038
Joined: Sat Jan 12, 2008 12:18 pm UTC

Re: Coding: Fleeting Thoughts

Postby Steax » Thu May 31, 2012 3:01 am UTC

Shivahn wrote:Well, right now I'm writing a component-entity system for a 2D game idea I have. It's a bit of an ongoing project that is honestly probably never going to get finished. Though I'm finally at the point where if I wanted to I could start adding content rather than framework (for example, I could turn the current framework into pong in about ten minutes). It's in C++.

I really meant rather broadly though - I know it's a broad question, so broad as to be possibly useless, but even just knowing terms like "graph visualization" and other keywords that describe concepts that might be useful would help.

(Also, my commenting probably needs work. It's pretty minimalist right now: I need to make sure I'll get it in three months)


I can't think of any off the top of my head, sorry. I'll follow up if I can think of anything Graph visualization is useful, yes... Though I think all programmers should get used to using pencil and paper to plan out their things. Automated tools are great, but sub-optimal.

sourmìlk wrote:So I have a getEntityByComponentTypes() function that takes (n > 0) template arguments.


I'm too sleepy at the moment to parse your paragraph, since I don't do that stuff, but please, for the love of everything, just call it "a function that takes one or more template arguments." I start to get really annoyed when people use math notation for anything trivial because it makes my thinking have to switch gears for absolutely no reason.
In Minecraft, I use the username Rirez.

User avatar
sourmìlk
If I can't complain, can I at least express my fear?
Posts: 6393
Joined: Mon Dec 22, 2008 10:53 pm UTC
Location: permanently in the wrong
Contact:

Re: Coding: Fleeting Thoughts

Postby sourmìlk » Fri Jun 01, 2012 4:17 am UTC

Steax wrote:
sourmìlk wrote:So I have a getEntityByComponentTypes() function that takes (n > 0) template arguments.


I'm too sleepy at the moment to parse your paragraph, since I don't do that stuff, but please, for the love of everything, just call it "a function that takes one or more template arguments." I start to get really annoyed when people use math notation for anything trivial because it makes my thinking have to switch gears for absolutely no reason.

Sorry, I've been programming a lot lately so my mind was in the more mathematical notation mode by default. I honestly didn't even think of saying "at least one."

EDIT:

In another thread, we were discussing a function that took the following container as an argument:

Code: Select all

Map<String, Map<String, ArrayList<Object>>>


And I was thinking of a container I have in one of my classes:

Code: Select all

map<string, pair<uint, uint>>

Do you think that's justifiable? (As for the use, it maps the name of an IBO to its ID and Size.)
Terry Pratchett wrote:The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it.

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Sun Jun 03, 2012 1:02 am UTC

sourmìlk wrote:In another thread, we were discussing a function that took the following container as an argument:

Code: Select all

Map<String, Map<String, ArrayList<Object>>>

It isn't wrong (but it smells). I'd prefer

Code: Select all

Map<Pair<String, String>, ArrayList<Object> >


sourmìlk wrote:

Code: Select all

map<string, pair<uint, uint>>

Do you think that's justifiable? (As for the use, it maps the name of an IBO to its ID and Size.)


No complaints from me. But others may disagree.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Coding: Fleeting Thoughts

Postby EvanED » Sun Jun 03, 2012 1:11 am UTC

You, sir, name? wrote:
sourmìlk wrote:In another thread, we were discussing a function that took the following container as an argument:

Code: Select all

Map<String, Map<String, ArrayList<Object>>>

It isn't wrong, but I'd prefer

Code: Select all

Map<Pair<String, String>, ArrayList<Object> >

There's may be good reason to prefer former. It's almost like a curried function. (If you view map<A, B> to be a function from an A to a B -- which it pretty much is -- then it basically exactly is a curried function.)

sourmìlk wrote:

Code: Select all

map<string, pair<uint, uint>>

Do you think that's justifiable? (As for the use, it maps the name of an IBO to its ID and Size.)


No complaints from me. But others may disagree.

There's always a tension between "do I just use std::pair (or whatever your language's equivalent is) or do I go to the overhead of writing a dumb replacement for pair so that I can give it better names than first and second? I never know what the right answer is. Clearly what we need is something like

Code: Select all

template<typename FirstType, identifier FirstName, typename SecondType, identifier SecondName>
struct pair {
    FirstType FirstName;
    SecondType SecondName;
};

pair<int, id, int, size> p;
p.id = 5;
p.size = 10;

(Note: I'm joking. I think.)

More seriously, if that's C++ though and not Java, I'd suggest a typedef:

Code: Select all

typedef pair<uint, uint> IdSizePair;
map<string, IdSizePair> ...

or something like that. Will make it harder to mess up what first and second mean.

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Sun Jun 03, 2012 1:30 am UTC

EvanED wrote:
You, sir, name? wrote:
sourmìlk wrote:In another thread, we were discussing a function that took the following container as an argument:

Code: Select all

Map<String, Map<String, ArrayList<Object>>>

It isn't wrong, but I'd prefer

Code: Select all

Map<Pair<String, String>, ArrayList<Object> >

There's may be good reason to prefer former. It's almost like a curried function. (If you view map<A, B> to be a function from an A to a B -- which it pretty much is -- then it basically exactly is a curried function.)


I guess it depends on the map implementation and data distribution, but I don't think you in general actually gain too much from doing this (especially if that is a hash map).
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
Steax
SecondTalon's Goon Squad
Posts: 3038
Joined: Sat Jan 12, 2008 12:18 pm UTC

Re: Coding: Fleeting Thoughts

Postby Steax » Sun Jun 03, 2012 5:34 am UTC

Interesting code golf solutions. They're probably nothing new, but I haven't been around code golf a lot, so I found it amusing.
In Minecraft, I use the username Rirez.

User avatar
Steax
SecondTalon's Goon Squad
Posts: 3038
Joined: Sat Jan 12, 2008 12:18 pm UTC

Re: Coding: Fleeting Thoughts

Postby Steax » Tue Jun 05, 2012 2:22 pm UTC

So while randomly browsing instapaper, I came across Jeff Atwood's article on Chaos Monkeys. Basically a thing that just randomly takes down servers, overloads a service, sends crap data, tries random bits of things, etc.

And since I'm already building a testing suite for my new PHP unframework (based on Flourish), today shall be the glorious day in which I create the file sfChaosMonkey.php.

Code: Select all


<?php
// tell the monkey to randomly check that link a ramdom number of times, presumably with an integer, but, well, it's a monkey
sfChaosMonkey::feedURL("http://test.example.com/project/pages/%i/");  

// tell the monkey to randomly submit a HTTP request through POST to that URL with presumably those arguments
sfChaosMonkey::feedHttp("POST""http://test.example.com/project/pages/create/", array("title" => "%s""body" => "%s"));
?>


Of course, it'll randomly latch on arguments, send malformed data, send weird headers, and other things... Randomly. It should be run on cron regularly for maximum hell. This will be interesting.
In Minecraft, I use the username Rirez.

User avatar
Sc4Freak
Posts: 673
Joined: Thu Jul 12, 2007 4:50 am UTC
Location: Redmond, Washington

Re: Coding: Fleeting Thoughts

Postby Sc4Freak » Tue Jun 05, 2012 5:49 pm UTC

Looks like a form of fuzz testing.

User avatar
Steax
SecondTalon's Goon Squad
Posts: 3038
Joined: Sat Jan 12, 2008 12:18 pm UTC

Re: Coding: Fleeting Thoughts

Postby Steax » Tue Jun 05, 2012 6:02 pm UTC

It is, but it's designed to be run on a live testing server instead of as a standalone test. The point of a chaos monkey is that nobody knows when it'll break the server, so it's more than just a code-level test; it challenges crisis management, server admins, data retrieval etc.

Advanced versions of the monkey may even be able to delete files at random or hold database/file locks.
In Minecraft, I use the username Rirez.

User avatar
Link
Posts: 1399
Joined: Sat Mar 07, 2009 11:33 am UTC
Location: ᘝᓄᘈᖉᐣ
Contact:

Re: Coding: Fleeting Thoughts

Postby Link » Tue Jun 05, 2012 10:17 pm UTC

CFT: I recently discovered OpenMP, which is pretty damn useful! It's a shame it's not possible to jump out of parallelised loops, or at least to let it stop spawning new threads once a condition is met, but other than that, it's quite cool. Multithreading tends to be a pretty complicated subject even for simple cases, but OpenMP essentially turns it into "instant parallelisation, just add #pragma".

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Tue Jun 05, 2012 10:47 pm UTC

Link wrote:CFT: I recently discovered OpenMP, which is pretty damn useful! It's a shame it's not possible to jump out of parallelised loops, or at least to let it stop spawning new threads once a condition is met, but other than that, it's quite cool. Multithreading tends to be a pretty complicated subject even for simple cases, but OpenMP essentially turns it into "instant parallelisation, just add #pragma".


Yeah I know. In most cases, its parallelism-abstraction is just so much more programmer friendly than the thread concept.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
Shivahn
Posts: 2200
Joined: Tue Jan 06, 2009 6:17 am UTC

Re: Coding: Fleeting Thoughts

Postby Shivahn » Wed Jun 06, 2012 4:25 pm UTC

Link wrote:CFT: I recently discovered OpenMP, which is pretty damn useful! It's a shame it's not possible to jump out of parallelised loops, or at least to let it stop spawning new threads once a condition is met, but other than that, it's quite cool. Multithreading tends to be a pretty complicated subject even for simple cases, but OpenMP essentially turns it into "instant parallelisation, just add #pragma".

Hmm, thanks for linking this.

I have an unrelated FT/question. In C++, if I'm using a vector which will have components added to and removed from it semi-regularly (but not nearly as often as it's iterated through), how should I handle that? Is keeping a list of open slots a good way?

User avatar
Sc4Freak
Posts: 673
Joined: Thu Jul 12, 2007 4:50 am UTC
Location: Redmond, Washington

Re: Coding: Fleeting Thoughts

Postby Sc4Freak » Wed Jun 06, 2012 6:14 pm UTC

Do you care about ordering? If not, then when you remove a component just swap it with the last element and then remove the last element. That makes removal an O(1) operation.

User avatar
Shivahn
Posts: 2200
Joined: Tue Jan 06, 2009 6:17 am UTC

Re: Coding: Fleeting Thoughts

Postby Shivahn » Wed Jun 06, 2012 6:19 pm UTC

Oh, that makes more sense! Ordering doesn't matter within a vector (each vector contains stuff that doesn't interact with each other in a way that changes state.)

Thanks, I'll do that!

Ben-oni
Posts: 278
Joined: Mon Sep 26, 2011 4:56 am UTC

Re: Coding: Fleeting Thoughts

Postby Ben-oni » Wed Jun 06, 2012 6:24 pm UTC

Shivahn wrote:I have an unrelated FT/question. In C++, if I'm using a vector which will have components added to and removed from it semi-regularly (but not nearly as often as it's iterated through), how should I handle that? Is keeping a list of open slots a good way?

Probably not. First, any machinery for optimizing the data structure's operations for your task should be done within the data structure, so if you need more speed, implement a new class.

If you are implementing a new vector class, odds are it won't be faster. By having a list of empty locations in the vector, you incur an additional overhead on iteration, which is the more common task. Adding or removing at the end of the vector takes constant time (amortized), so there's no benefit. On the other hand, shuffling around data within the vector takes N time, but the benefit of reducing this to a constant is probably negligible if iteration is more common.

It's usually best to optimize those loops your program spends most of its time in.

User avatar
Yakk
Poster with most posts but no title.
Posts: 11115
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Wed Jun 06, 2012 8:53 pm UTC

Speaking of parallel code...

Take a look at microsofts amp project:
http://msdn.microsoft.com/en-us/library ... 10%29.aspx
it (ab)uses the restrict keyword (so you can say "this function is restricted to using a reduced feature set of the language", which they need to be able to reasonably run code on the GPU).

From that, we get:

Code: Select all

parallel_for_each( details, [=](index<1> idx) restrict(amp)
{
  // code goes here
});

where we can use for-each and lambdas to run code on the GPU, or in in a more traditional multiple process environment.

Rather neat solution, as it allows expression "this function must come from some restricted set of C++". The big thing missing is an in-language way to describe a set of restrictions, as opposed to compiler-provided methods.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

User avatar
Xanthir
My HERO!!!
Posts: 5400
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: Coding: Fleeting Thoughts

Postby Xanthir » Wed Jun 06, 2012 11:22 pm UTC

Woohoo! Every web dev rejoice, today my Flexbox Layout CSS spec was approved to go to Last Call! It'll be published on Tuesday, so on July 3rd it'll move to Candidate Rec, and all the browsers can unprefix it!

Right now, only Chrome has a public implementation of the new draft, and we're about to change to match the naming changes that have happened in the past month, which will break pretty much everything currently using Flexbox. Once we do that, though, we'll be stable and unprefixed in a mere few weeks! All the other browsers have implementations ready to go as well - FF and Opera were basically just waiting for the spec to stabilize, so should release unprefixed support in a month or two as well. Even IE10 will support it, though right now the plan is to do so under the -ms- prefix (who knows if that'll change, though).

By the end of this year, you'll be able to use Flexbox in every major browser! Wooooooo!
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 21 guests