Programmers: up for a SDN weird code challenge?

GEC: Discuss gaming, computers and electronics and venture into the bizarre world of STGODs.

Moderator: Thanas

User avatar
Pu-239
Sith Marauder
Posts: 4727
Joined: 2002-10-21 08:44am
Location: Fake Virginia

Post by Pu-239 »

Anyone try Ruby on Rails?

ah.....the path to happiness is revision of dreams and not fulfillment... -SWPIGWANG
Sufficient Googling is indistinguishable from knowledge -somebody
Anything worth the cost of a missile, which can be located on the battlefield, will be shot at with missiles. If the US military is involved, then things, which are not worth the cost if a missile will also be shot at with missiles. -Sea Skimmer


George Bush makes freedom sound like a giant robot that breaks down a lot. -Darth Raptor
Miles Teg
Padawan Learner
Posts: 300
Joined: 2002-07-21 06:11pm

Post by Miles Teg »

Dooey Jo wrote:What's wrong with PHP?
The quick and dirty run down:

* No formal language spec or conventions.

* No namespaces

* Dynamic typing is never a good thing for anything other than a one person project (and even then not great).

* Shit poor security model

That said, if they could fix the security issues, it would be an ok language for small projects.

Miles Teg
Now I am become death -- the shatterer of worlds...
-- Oppenheimer 1945
User avatar
Faram
Bastard Operator from Hell
Posts: 5271
Joined: 2002-07-04 07:39am
Location: Fighting Polarbears

Post by Faram »

Sticky for a bit.
[img=right]http://hem.bredband.net/b217293/warsaban.gif[/img]

"Either God wants to abolish evil, and cannot; or he can, but does not want to. ... If he wants to, but cannot, he is impotent. If he can, but does not want to, he is wicked. ... If, as they say, God can abolish evil, and God really wants to do it, why is there evil in the world?" -Epicurus


Fear is the mother of all gods.

Nature does all things spontaneously, by herself, without the meddling of the gods. -Lucretius
User avatar
Pu-239
Sith Marauder
Posts: 4727
Joined: 2002-10-21 08:44am
Location: Fake Virginia

Post by Pu-239 »

Miles Teg wrote:
Dooey Jo wrote:What's wrong with PHP?
The quick and dirty run down:

* No formal language spec or conventions.

* No namespaces

* Dynamic typing is never a good thing for anything other than a one person project (and even then not great).

* Shit poor security model

That said, if they could fix the security issues, it would be an ok language for small projects.

Miles Teg
What about Python? And I'm a bit confused about strong vs weak typing and dynamic and static typing

ah.....the path to happiness is revision of dreams and not fulfillment... -SWPIGWANG
Sufficient Googling is indistinguishable from knowledge -somebody
Anything worth the cost of a missile, which can be located on the battlefield, will be shot at with missiles. If the US military is involved, then things, which are not worth the cost if a missile will also be shot at with missiles. -Sea Skimmer


George Bush makes freedom sound like a giant robot that breaks down a lot. -Darth Raptor
User avatar
Beowulf
The Patrician
Posts: 10621
Joined: 2002-07-04 01:18am
Location: 32ULV

Post by Beowulf »

Dynamic typing is the type of a variable not being determined until it's used. A string "45" can be used as a number 45. Static typing is every variable having a type that can't be changed.

Strong typing is the prevention of mixing types in an operation: string "45" + numeral 1, for example. Weak typing is the reverse. I could increment the string "45" and get "46" back.

Dynamic typing isn't entirely bad. It's an essential feature of polymorphism. If you've never used polymorphism in a project, I'd suggest you learn OO programming.
"preemptive killing of cops might not be such a bad idea from a personal saftey[sic] standpoint..." --Keevan Colton
"There's a word for bias you can't see: Yours." -- William Saletan
User avatar
Pu-239
Sith Marauder
Posts: 4727
Joined: 2002-10-21 08:44am
Location: Fake Virginia

Post by Pu-239 »

Beowulf wrote:Dynamic typing is the type of a variable not being determined until it's used. A string "45" can be used as a number 45. Static typing is every variable having a type that can't be changed.

Strong typing is the prevention of mixing types in an operation: string "45" + numeral 1, for example. Weak typing is the reverse. I could increment the string "45" and get "46" back.

Dynamic typing isn't entirely bad. It's an essential feature of polymorphism. If you've never used polymorphism in a project, I'd suggest you learn OO programming.
But what's especially bad about it?

ah.....the path to happiness is revision of dreams and not fulfillment... -SWPIGWANG
Sufficient Googling is indistinguishable from knowledge -somebody
Anything worth the cost of a missile, which can be located on the battlefield, will be shot at with missiles. If the US military is involved, then things, which are not worth the cost if a missile will also be shot at with missiles. -Sea Skimmer


George Bush makes freedom sound like a giant robot that breaks down a lot. -Darth Raptor
User avatar
Beowulf
The Patrician
Posts: 10621
Joined: 2002-07-04 01:18am
Location: 32ULV

Post by Beowulf »

Pu-239 wrote:
Beowulf wrote:Dynamic typing is the type of a variable not being determined until it's used. A string "45" can be used as a number 45. Static typing is every variable having a type that can't be changed.

Strong typing is the prevention of mixing types in an operation: string "45" + numeral 1, for example. Weak typing is the reverse. I could increment the string "45" and get "46" back.

Dynamic typing isn't entirely bad. It's an essential feature of polymorphism. If you've never used polymorphism in a project, I'd suggest you learn OO programming.
But what's especially bad about it?
It's hard to tell what type an object is. Which makes it easier to do something you didn't mean to do.
"preemptive killing of cops might not be such a bad idea from a personal saftey[sic] standpoint..." --Keevan Colton
"There's a word for bias you can't see: Yours." -- William Saletan
User avatar
Pu-239
Sith Marauder
Posts: 4727
Joined: 2002-10-21 08:44am
Location: Fake Virginia

Post by Pu-239 »

Beowulf wrote:
Pu-239 wrote:
Beowulf wrote:Dynamic typing is the type of a variable not being determined until it's used. A string "45" can be used as a number 45. Static typing is every variable having a type that can't be changed.

Strong typing is the prevention of mixing types in an operation: string "45" + numeral 1, for example. Weak typing is the reverse. I could increment the string "45" and get "46" back.

Dynamic typing isn't entirely bad. It's an essential feature of polymorphism. If you've never used polymorphism in a project, I'd suggest you learn OO programming.
But what's especially bad about it?
It's hard to tell what type an object is. Which makes it easier to do something you didn't mean to do.
That's it? Doesn't anybody use comments (and meaningful variable names)? :P

ah.....the path to happiness is revision of dreams and not fulfillment... -SWPIGWANG
Sufficient Googling is indistinguishable from knowledge -somebody
Anything worth the cost of a missile, which can be located on the battlefield, will be shot at with missiles. If the US military is involved, then things, which are not worth the cost if a missile will also be shot at with missiles. -Sea Skimmer


George Bush makes freedom sound like a giant robot that breaks down a lot. -Darth Raptor
User avatar
Mad
Jedi Council Member
Posts: 1923
Joined: 2002-07-04 01:32am
Location: North Carolina, USA
Contact:

Post by Mad »

Looks like the current them is stuff that changes text input around.

Here's a quick submission. This is an essay rewriter. Takes sentence phrases (separated by punctuation) and reorganizes them into a few paragraphs. So you can convert a long, boring essay into something hopefully more fun.

Of course, the real fun that I had was doing this with no braces in the source code (except the ones required for main(), of course). (There's also the boring, readable, class-using version I whipped up first. But what fun is that?)

It reads from standard input and sends to standard output. Either redirect from a file or use CTRL+Z on an empty line in Windows to end. (If you're running UNIX or Linux, the key combo to signal end of input is different, but you should already know it. :P)

C++ source compiled and tested using GCC 3.3.2 on Windows (MinGW) and Solaris (g++).

Code: Select all

#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#define BRACES_ARE {
#define FOR_CHUMPS }
using namespace std;
const string SENTENCE_END = ".!?";
const string SENTENCE_MIDDLE = ",;:";
int main(int argc, char *argv[]) BRACES_ARE
string source_string;
string rewritten;
vector<string> starter;
vector<string> middle;
vector<string> ender;
vector<string> simple;
srand(0);
while(cin) source_string += cin.get();
int num_fragments = 0;
string fragment;
bool cont = false;
bool makezero = false;
bool clearit = false;
string::const_iterator p;
for(p = source_string.begin(); p != source_string.end(); ++p)
if(!(fragment.empty() && isspace(*p)))
goto tehwoot;
else
ret: continue;
goto ohdone;
tehwoot:
clearit = false;
makezero = false;
fragment += *p;
if(SENTENCE_END.find(*p) != string::npos &&
(clearit = true) && (makezero = true))
if(++num_fragments == 1)
simple.push_back(fragment);
else
ender.push_back(fragment);
else if(SENTENCE_MIDDLE.find(*p) != string::npos && (clearit = true))
if(++num_fragments == 1)
starter.push_back(fragment);
else
middle.push_back(fragment);
if(clearit) fragment.clear();
if(makezero) num_fragments = 0;
goto ret;
ohdone:
if(starter.size() == 0) starter.push_back("Hello,");
if(middle.size() == 0) middle.push_back("if you didn't know,");
if(ender.size() == 0) ender.push_back("braces suck!");
if(simple.size() == 0) simple.push_back("That is all.");
for(int i=0; i<3; ++i, rewritten += "\n\n")
for(int j=0, n=rand()%5-1; j<10; ++j, n = rand()%5-1)
if(n == -1)
rewritten += simple[rand()%simple.size()]+ " ";
else
for(int k=0; k<n; ++k, rewritten += ender[rand()%ender.size()] + " ")
if(!k) rewritten += starter[rand()%starter.size()] + " " +
middle[rand()%middle.size()] + " ";
else rewritten += middle[rand()%middle.size()] + " ";
cout << "Moblin says: Jumble, jumble..." << endl << endl;
cout << rewritten << endl;
return EXIT_SUCCESS; FOR_CHUMPS;
Later...
Miles Teg
Padawan Learner
Posts: 300
Joined: 2002-07-21 06:11pm

Post by Miles Teg »

Pu-239 wrote:
Beowulf wrote:
Pu-239 wrote: But what's especially bad about it?
It's hard to tell what type an object is. Which makes it easier to do something you didn't mean to do.
That's it? Doesn't anybody use comments (and meaningful variable names)? :P
lol Of course they do!

Dynamic typing tends to lead to large amount of runtime errors, whereas static typing tends to reduce runtime errors because they are caught at compile time. (Compilers are infinitely better at catching errors than any human will ever be). It basically boils down to this: In a statically typed language I feel its easier to concentrate on solving a problem because I can let the compiler deal with making sure I'm not trying to find the square root of "A" because some schmuck passed my function a string instead of an int ;-)

Miles Teg
Now I am become death -- the shatterer of worlds...
-- Oppenheimer 1945
User avatar
Mad
Jedi Council Member
Posts: 1923
Joined: 2002-07-04 01:32am
Location: North Carolina, USA
Contact:

Post by Mad »

In addition, if the interpreter is constantly casting the variable as different types, the program will run slower.

Some editors can list the members and methods of classes or structures while typing an identifier to them elsewhere in the source. Of course, in order to make use of that, the editor has to know what the identifier is referring to.
Later...
User avatar
Mad
Jedi Council Member
Posts: 1923
Joined: 2002-07-04 01:32am
Location: North Carolina, USA
Contact:

Post by Mad »

No more entries? Lack of ideas/direction? (Lack of time?)
Later...
User avatar
Dooey Jo
Sith Devotee
Posts: 3127
Joined: 2002-08-09 01:09pm
Location: The land beyond the forest; Sweden.
Contact:

Post by Dooey Jo »

I could post the code for the game I'm currently writing. Only it's probably around 20 000 lines or so :wink:
Image
"Nippon ichi, bitches! Boing-boing."
Mai smote the demonic fires of heck...

Faker Ninjas invented ninjitsu
User avatar
Chris OFarrell
Durandal's Bitch
Posts: 5724
Joined: 2002-08-02 07:57pm
Contact:

Post by Chris OFarrell »

I was going to paste this work of horrible art as a slab of text...but I'll be nice and seperate it a little.

I'm curious to see who can work it out WITHOUT dumping it into a compiler.


#define C1 1000

#include<stdio.h>

int main()
{
int A1[C1],I1,I2,I3,I4,I5,I6,I7;
A1[0]=2;I2=1;
scanf("%d",&I1);
I3=1; I6=0; I7=4;
for(;I2<I1;I2++)
{
I4=0;

L1:
I3+=2; I5=0;
if(I3>=I7)
{
I6++; I7=A1[I6]*A1[I6];
}

do I5++;
while(I5<I6&&I3%A1[I5]!=0);

if(I5>=I6)I4=1;

if(!I4)goto L1;
A1[I2]=I3;
}

I2=0;
L2:

printf("%8d",A1[I2]);
I2++;
if(I2%10==0)printf("\n");
if(I2!=I1)goto L2;
if(I1%10!=0)printf("\n");

return 0;

}
User avatar
phongn
Rebel Leader
Posts: 18487
Joined: 2002-07-03 11:11pm

Post by phongn »

Can I find a C interpreter and do that instead? :lol:
User avatar
Mad
Jedi Council Member
Posts: 1923
Joined: 2002-07-04 01:32am
Location: North Carolina, USA
Contact:

Post by Mad »

phongn wrote:Can I find a C interpreter and do that instead? :lol:
That's cheating. You have to convert it to a different language and run it through that compiler instead. I choose C++. :mrgreen:

Oh, and it crashes if you enter a number that's too big, that's what it does.

Actually, I figured out the first three numbers by running it through my head and took a guess from there. I ran it and was correct.

Big hint (but not as big as running it :P): they're pretty easy because a lot of logic used later is skipped for the first numbers. Things get more complex after that, but the first numbers tell you all you need to know. The guess is assuming the rest of the code works, because if it doesn't, I'd be wrong.
Later...
User avatar
Durandal
Bile-Driven Hate Machine
Posts: 17927
Joined: 2002-07-03 06:26pm
Location: Silicon Valley, CA
Contact:

Post by Durandal »

Miles Teg wrote:* No namespaces
Frankly, I couldn't give two shits about namespaces. They're designed to solve a problem that is the result of poor design: conflicting function names. I prefix all my class methods with a class acronym. WOW! I just made namespaces totally redundant!
Damien Sorresso

"Ever see what them computa bitchez do to numbas? It ain't natural. Numbas ain't supposed to be code, they supposed to quantify shit."
- The Onion
User avatar
Chris OFarrell
Durandal's Bitch
Posts: 5724
Joined: 2002-08-02 07:57pm
Contact:

Post by Chris OFarrell »

Durandal wrote:
Miles Teg wrote:* No namespaces
Frankly, I couldn't give two shits about namespaces. They're designed to solve a problem that is the result of poor design: conflicting function names. I prefix all my class methods with a class acronym. WOW! I just made namespaces totally redundant!
You use common sense instead of an over the top, insane, elaborate....oh right, you work for Apple instead of Microsoft no? :)
User avatar
Durandal
Bile-Driven Hate Machine
Posts: 17927
Joined: 2002-07-03 06:26pm
Location: Silicon Valley, CA
Contact:

Post by Durandal »

I feel the same way about multiple inheritance. Talk about a feature that is completely useless for 99% of programmers. "OMG I'VE GOT CONFLICTING ATTRIBUTES!" Well design your class structure better next time.
Damien Sorresso

"Ever see what them computa bitchez do to numbas? It ain't natural. Numbas ain't supposed to be code, they supposed to quantify shit."
- The Onion
User avatar
Pu-239
Sith Marauder
Posts: 4727
Joined: 2002-10-21 08:44am
Location: Fake Virginia

Post by Pu-239 »

Durandal wrote:
Miles Teg wrote:* No namespaces
Frankly, I couldn't give two shits about namespaces. They're designed to solve a problem that is the result of poor design: conflicting function names. I prefix all my class methods with a class acronym. WOW! I just made namespaces totally redundant!
Well, it makes for less typing... I think? Don't have to type the prefix on everything, and it can be changed later w/o mass renaming. Also you have 3rd party libraries who's names may conflict...

ah.....the path to happiness is revision of dreams and not fulfillment... -SWPIGWANG
Sufficient Googling is indistinguishable from knowledge -somebody
Anything worth the cost of a missile, which can be located on the battlefield, will be shot at with missiles. If the US military is involved, then things, which are not worth the cost if a missile will also be shot at with missiles. -Sea Skimmer


George Bush makes freedom sound like a giant robot that breaks down a lot. -Darth Raptor
User avatar
phongn
Rebel Leader
Posts: 18487
Joined: 2002-07-03 11:11pm

Post by phongn »

Durandal wrote:I feel the same way about multiple inheritance. Talk about a feature that is completely useless for 99% of programmers. "OMG I'VE GOT CONFLICTING ATTRIBUTES!" Well design your class structure better next time.
Bah. I like namespaces, though I know they are abused. As for multiple inheritance - I can't tell if you say it's a good thing or bad thing?
User avatar
Mad
Jedi Council Member
Posts: 1923
Joined: 2002-07-04 01:32am
Location: North Carolina, USA
Contact:

Post by Mad »

Durandal wrote:
Miles Teg wrote:* No namespaces
Frankly, I couldn't give two shits about namespaces. They're designed to solve a problem that is the result of poor design: conflicting function names. I prefix all my class methods with a class acronym. WOW! I just made namespaces totally redundant!
In that case, is "boost::regex" really so much harder to type than "boost_regex"?

In any case, namespaces are just a natural extension of scoping rules. Why not just have a bunch of global variables each prefixed with the function they belong to? Then you won't have any conflicting variable names and you can use them whenever you need to. :P (The correct answer is "that's stupid, and it prohibits recursion.")

Code inside a namespace looks a lot cleaner without class prefixes dangling around everywhere. (Sorta like you're probably glad you don't have to use this to reference methods and members... unless you're using PHP.)
Later...
User avatar
Durandal
Bile-Driven Hate Machine
Posts: 17927
Joined: 2002-07-03 06:26pm
Location: Silicon Valley, CA
Contact:

Post by Durandal »

Mad wrote:In that case, is "boost::regex" really so much harder to type than "boost_regex"?
No, but "boost_regex" looks nicer. :D
In any case, namespaces are just a natural extension of scoping rules. Why not just have a bunch of global variables each prefixed with the function they belong to? Then you won't have any conflicting variable names and you can use them whenever you need to. :P (The correct answer is "that's stupid, and it prohibits recursion.")
The other correct answer would be that variable names are reused far more frequently than function names. See 'i', 'j' and 'k'. My personal favorite is from the guide to writing unmaintainable code.

marypoppins = superman + starship / god;
Code inside a namespace looks a lot cleaner without class prefixes dangling around everywhere. (Sorta like you're probably glad you don't have to use this to reference methods and members... unless you're using PHP.)
Actually, being an Mac OS X developer, I work in Objective-C. When calling an internal method, you send the message [self methodName]. Makes it easy to tell where the call is coming from. Since method calls are actually messages, you can have two different classes have the same method names without any need for scoping.

By the way, I take it that everyone here has read the Guide to Writing Unmaintainable Code?
Damien Sorresso

"Ever see what them computa bitchez do to numbas? It ain't natural. Numbas ain't supposed to be code, they supposed to quantify shit."
- The Onion
User avatar
Dooey Jo
Sith Devotee
Posts: 3127
Joined: 2002-08-09 01:09pm
Location: The land beyond the forest; Sweden.
Contact:

Post by Dooey Jo »

Destructionator XIII wrote:The awesome part is 16k is so pathetic. Even the NES had 64k of memory, in addition to the sprite buffer. There's an idea to get around the framebuffer issues: force you to use sprites like the NES did.
Heh, you think 16k is pathetic? Try the Atari 2600. It had 128. Bytes! And 4k of ROM storage. Now that's shit :lol:
Am I the only one who thinks this would be fun as hell, or does it sound like a good challenge?
It sure sounds challenging... Though on the topic of NES, I think it would be cool to make some kind of (un)official SDN NES game or something...
Image
"Nippon ichi, bitches! Boing-boing."
Mai smote the demonic fires of heck...

Faker Ninjas invented ninjitsu
User avatar
Mad
Jedi Council Member
Posts: 1923
Joined: 2002-07-04 01:32am
Location: North Carolina, USA
Contact:

Post by Mad »

Destructionator XIII wrote:Still, I'd be willing to try a SDN NES game.
Now that would rock.
Later...
Post Reply