Friday, July 22, 2016

Writing a C Program, the Dummy Version

programming in the C language not C++ not C#
programming in the C language: not C++; not C#
Back in olden days, when knights and knaves ruled the land and personal disputes were settled with broadswords instead of Glock 17s, only a few learned folk knew how to code; or, as we called it in those days, "program a computer." Now everyone (thinks he or she) knows how to code, although being able to move colored boxes around isn't actually coding... but we digress. Some of the early eHowians liked to pretend this skill as well, including first-timer Victor Fonseca. We know Fonseca was a coding dumbass because we've read the content he wrote for "How to Delete a File in C."¹ Let's just  say, it was pretty obvious...

...obvious from the very first sentence in the post:
C++ is considered a highly adaptable, middle-level programming language."
Did Victor not know that C and C++ are different programming languages? Apparently he didn't! Fortunately for Vic, the necessary library and functions are often the same in the two languages, probably because they're so basic (not BASIC, mind you: a little programming joke for you people who think Ruby on Rails is old). Anyway, it would be fortunate if he'd gotten it right.

You see, Fonseca – who's unlikely to have taken a programming course while getting that PolySci degree – simply found a reference somewhere for the remove library function in C (or C++) and tried to rewrite it to prevent claims of plagiarism. And here's how he restated it (word for word, letter for letter):
  • Access your key menu. (WTF is a "key menu," anyway?)
  • Type the following code: #include, then press "enter."
  • Type the following code: int main(), then press enter and add a { value.
  • Type the following code: if(remove("filetobedeleted.txt") == -1), where "filetobedeleted.txt" is the name and extension of the file you want deleted. Press "enter" and add a { value.
  • Type the following code: fprintf(stderr,"Remove failed"); -- press "enter" -- then type: exit(EXIT_FAILURE); press "enter" and add a } value.
  • Press "enter," then type the following code: exit(EXIT_SUCCESS); -- press "enter" -- then add a } value.
   
That mishmash of bullshit turns out to produce the following code snippet:

#include
int main()
{
if(remove("filetobedeleted.txt") == -1)
}
fprintf(stderr,"Remove failed");
exit(EXIT_FAILURE);
{
exit(EXIT_SUCCESS);
}

Which... well, it has a few errors: 
  1. It's crappy programming; "elegant" and "showy" but without comments, nothing is explained
  2. Victor is... ummm, not so good with spacing and indentation?
  3. There's no return statement
  4. He neither compiles nor runs the code (obviously)
In other words, it won't run: we checked the code with an online C compiler, and it failed miserably. But that's OK, it doesn't compile in C++, either! That means that not only did Fonseca fail to note the difference between the C and C++ languages (heaven forbid he found out that there's also a C# language), he even got his ripped-off code wrong. Can you think of a more deserving Dumbass of the Day? We can't...

¹ The original has been deleted by Leaf Group, but can still be accessed using the Wayback machine at archive.org. Its URL was    ehow.com/how_5068114_delete-file-c.html
copyright © 2016-2022 scmrak

DD - CODING

No comments: