Programmers: up for a SDN weird code challenge?
Moderator: Thanas
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
The quick and dirty run down:Dooey Jo wrote:What's wrong with PHP?
* 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
-- Oppenheimer 1945
- Faram
- Bastard Operator from Hell
- Posts: 5271
- Joined: 2002-07-04 07:39am
- Location: Fighting Polarbears
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
"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
What about Python? And I'm a bit confused about strong vs weak typing and dynamic and static typingMiles Teg wrote:The quick and dirty run down:Dooey Jo wrote:What's wrong with PHP?
* 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
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
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.
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
"There's a word for bias you can't see: Yours." -- William Saletan
But what's especially bad about it?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.
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
It's hard to tell what type an object is. Which makes it easier to do something you didn't mean to do.Pu-239 wrote:But what's especially bad about it?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.
"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
"There's a word for bias you can't see: Yours." -- William Saletan
That's it? Doesn't anybody use comments (and meaningful variable names)?Beowulf wrote:It's hard to tell what type an object is. Which makes it easier to do something you didn't mean to do.Pu-239 wrote:But what's especially bad about it?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.
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
- Mad
- Jedi Council Member
- Posts: 1923
- Joined: 2002-07-04 01:32am
- Location: North Carolina, USA
- Contact:
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. )
C++ source compiled and tested using GCC 3.3.2 on Windows (MinGW) and Solaris (g++).
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. )
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...
lol Of course they do!Pu-239 wrote:That's it? Doesn't anybody use comments (and meaningful variable names)?Beowulf wrote:It's hard to tell what type an object is. Which makes it easier to do something you didn't mean to do.Pu-239 wrote: But what's especially bad about it?
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
-- Oppenheimer 1945
- Mad
- Jedi Council Member
- Posts: 1923
- Joined: 2002-07-04 01:32am
- Location: North Carolina, USA
- Contact:
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.
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...
- Chris OFarrell
- Durandal's Bitch
- Posts: 5724
- Joined: 2002-08-02 07:57pm
- Contact:
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;
}
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;
}
- Mad
- Jedi Council Member
- Posts: 1923
- Joined: 2002-07-04 01:32am
- Location: North Carolina, USA
- Contact:
That's cheating. You have to convert it to a different language and run it through that compiler instead. I choose C++.phongn wrote:Can I find a C interpreter and do that instead?
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 ): 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...
- Durandal
- Bile-Driven Hate Machine
- Posts: 17927
- Joined: 2002-07-03 06:26pm
- Location: Silicon Valley, CA
- Contact:
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!Miles Teg wrote:* No namespaces
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
"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
- Chris OFarrell
- Durandal's Bitch
- Posts: 5724
- Joined: 2002-08-02 07:57pm
- Contact:
You use common sense instead of an over the top, insane, elaborate....oh right, you work for Apple instead of Microsoft no?Durandal wrote: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!Miles Teg wrote:* No namespaces
- Durandal
- Bile-Driven Hate Machine
- Posts: 17927
- Joined: 2002-07-03 06:26pm
- Location: Silicon Valley, CA
- Contact:
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
"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
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...Durandal wrote: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!Miles Teg wrote:* No namespaces
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
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?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.
- Mad
- Jedi Council Member
- Posts: 1923
- Joined: 2002-07-04 01:32am
- Location: North Carolina, USA
- Contact:
In that case, is "boost::regex" really so much harder to type than "boost_regex"?Durandal wrote: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!Miles Teg wrote:* No namespaces
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. (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...
- Durandal
- Bile-Driven Hate Machine
- Posts: 17927
- Joined: 2002-07-03 06:26pm
- Location: Silicon Valley, CA
- Contact:
No, but "boost_regex" looks nicer.Mad wrote:In that case, is "boost::regex" really so much harder to type than "boost_regex"?
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.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. (The correct answer is "that's stupid, and it prohibits recursion.")
marypoppins = superman + starship / god;
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.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.)
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
"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
- Dooey Jo
- Sith Devotee
- Posts: 3127
- Joined: 2002-08-09 01:09pm
- Location: The land beyond the forest; Sweden.
- Contact:
Heh, you think 16k is pathetic? Try the Atari 2600. It had 128. Bytes! And 4k of ROM storage. Now that's shitDestructionator 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.
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...Am I the only one who thinks this would be fun as hell, or does it sound like a good challenge?
"Nippon ichi, bitches! Boing-boing."
Mai smote the demonic fires of heck...
Faker Ninjas invented ninjitsu
Mai smote the demonic fires of heck...
Faker Ninjas invented ninjitsu