Advertisement

How knackered is your code paste

Started by February 17, 2012 04:55 AM
28 comments, last by swiftcoder 12 years, 10 months ago
That code paste is really ticking me off.
[attachment=7352:eve.png]

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

Okay, been following along and I have a question that has to do with the issue Washu raised. There are a lot of old but still often-referenced articles with source that is supposed to look like this:

[font=courier new,courier,monospace]long arr[10] = { 3,6,1,2,3,8,4,1,7,2};
char arr2[5][20] = {[nbsp][nbsp]"Mickey Mouse",
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]"Donald Duck",
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]"Minnie Mouse",
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]"Goofy",
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]"Ted Jensen" };

void bubble(void *p, int width, int N,
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]int(*fptr)(const void *, const void *));
int compare_string(const void *m, const void *n);
int compare_long(const void *m, const void *n);

int main(void)
{
[nbsp][nbsp][nbsp][nbsp]int i;
[nbsp][nbsp][nbsp][nbsp]puts("\nBefore Sorting:\n");

[nbsp][nbsp][nbsp][nbsp]for (i = 0; i [lessthan] 10; i++)[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp] /* show the long ints */
[nbsp][nbsp][nbsp][nbsp]{
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]printf("%ld ",arr[array='i']);
[nbsp][nbsp][nbsp][nbsp]}
[nbsp][nbsp][nbsp][nbsp]puts("\n");

[nbsp][nbsp][nbsp][nbsp]for (i = 0; i [lessthan] 5; i++)[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]/* show the strings */
[nbsp][nbsp][nbsp][nbsp]{
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]printf("%s\n", arr2[array='i']);
[nbsp][nbsp][nbsp][nbsp]}
[nbsp][nbsp][nbsp][nbsp]bubble(arr, 4, 10, compare_long);[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]/* sort the longs */
[nbsp][nbsp][nbsp][nbsp]bubble(arr2, 20, 5, compare_string);[nbsp][nbsp][nbsp][nbsp] /* sort the strings */
[nbsp][nbsp][nbsp][nbsp]puts("\n\nAfter Sorting:\n");

[nbsp][nbsp][nbsp][nbsp]for (i = 0; i [lessthan] 10; i++)[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp] /* show the sorted longs */
[nbsp][nbsp][nbsp][nbsp]{
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]printf("%d ",arr[array='i']);
[nbsp][nbsp][nbsp][nbsp]}
[nbsp][nbsp][nbsp][nbsp]puts("\n");

[nbsp][nbsp][nbsp][nbsp]for (i = 0; i [lessthan] 5; i++)[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]/* show the sorted strings */
[nbsp][nbsp][nbsp][nbsp]{
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]printf("%s\n", arr2[array='i']);
[nbsp][nbsp][nbsp][nbsp]}
[nbsp][nbsp][nbsp][nbsp]return 0;
}[/font]

But instead when you plain text paste it into the editor and wrap it in code tags it looks like this:

long arr[10] = { 3,6,1,2,3,8,4,1,7,2};
char arr2[5][20] = { "Mickey Mouse",
"Donald Duck",
"Minnie Mouse",
"Goofy",
"Ted Jensen" };

void bubble(void *p, int width, int N,
int(*fptr)(const void *, const void *));
int compare_string(const void *m, const void *n);
int compare_long(const void *m, const void *n);

int main(void)
{
int i;
puts("\nBefore Sorting:\n");

for (i = 0; i < 10; i++) /* show the long ints */
{
printf("%ld ",arr);
}
puts("\n");

for (i = 0; i < 5; i++) /* show the strings */
{
printf("%s\n", arr2);
}
bubble(arr, 4, 10, compare_long); /* sort the longs */
bubble(arr2, 20, 5, compare_string); /* sort the strings */
puts("\n\nAfter Sorting:\n");

for (i = 0; i < 10; i++) /* show the sorted longs */
{
printf("%d ",arr);
}
puts("\n");

for (i = 0; i < 5; i++) /* show the sorted strings */
{
printf("%s\n", arr2);
}
return 0;
}


Does that bother anyone else as much as it does me? I think I might just be a bit of a stickler for neatly-formatted code.

Also I don't use code boxes on the forums ever, mainly deal with them in articles where there is no source coloring for them. Does anyone else see a lot of comments in the above example that aren't really comments? I realize coloring is another personal preference but I've always thought green for comments was pretty universal as a default color

Drew Sikora
Executive Producer
GameDev.net

Advertisement

That code paste is really ticking me off.
[attachment=7352:eve.png]


I'm so confused...

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Here's a fun one, hold on to your seats:

Original code

#include <sfml/graphics.hpp>

template<class type>
class why_does_it_think_theres_html {
template<class i_dunno>
void foobar() {
/* ??? */
}
};


After pressing the edit button, my post looks like:

Here's a fun one, hold on to your seats:

Original code

#include <sfml graphics.hpp="">

template<class type="">
class why_does_it_think_theres_html {
template<class i_dunno="">
void foobar() {
/* ??? */
}
};


After pressing the edit button, my post looks like:</class></class></sfml>
[/quote]

Okay, been following along and I have a question that has to do with the issue Washu raised. There are a lot of old but still often-referenced articles with source that is supposed to look like this:

Does that bother anyone else as much as it does me? I think I might just be a bit of a stickler for neatly-formatted code.

Also I don't use code boxes on the forums ever, mainly deal with them in articles where there is no source coloring for them. Does anyone else see a lot of comments in the above example that aren't really comments? I realize coloring is another personal preference but I've always thought green for comments was pretty universal as a default color

I think you're a stickler for neatly formatted code. That being said, I think its probably the same issue at the core of the problem with the "code" block, which is that the forum post formatter isn't treating the code blocks as "raw stuff that I should escape but otherwise ignore."


Here's a fun one, hold on to your seats:

Original code

#include <sfml/graphics.hpp>

template<class type>
class why_does_it_think_theres_html {
template<class i_dunno>
void foobar() {
/* ??? */
}
};


After pressing the edit button, my post looks like:

Here's a fun one, hold on to your seats:

Original code

#include <sfml graphics.hpp="">

template<class type="">
class why_does_it_think_theres_html {
template<class i_dunno="">
void foobar() {
/* ??? */
}
};


After pressing the edit button, my post looks like:</class></class></sfml>

[/quote]
Yup yup, I get that A LOT.

[quote name='Washu' timestamp='1329690047' post='4914638']
That code paste is really ticking me off.
[attachment=7352:eve.png]

I'm so confused...
[/quote]
What, its gamedev.net... from eve.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.


Yeah, what's up with source tags? I can't figure out how to specify a language so that there's syntax highlighting.


See this Staff Journal post.

Drew Sikora
Executive Producer
GameDev.net

Advertisement

[quote name='swiftcoder' timestamp='1329690435' post='4914640']
[quote name='Washu' timestamp='1329690047' post='4914638']
That code paste is really ticking me off.
[attachment=7352:eve.png]


I'm so confused...
[/quote]
What, its gamedev.net... from eve.
[/quote]
Well... one gets the idea that the picture further explains/gives example of the code paste that's really ticking you off... but it doesn't.

[edit]

@Drew: Hmmm... I swore it wasn't working for me at one point. Anyway, the preview is kinda messed up. Here's the code I entered to test, and I took a screenshot of what I got for the preview.

[source lang="cpp"]
#include <iostream>

// Empty class
class X
{
};

int main()
{
std::cout << "Hello world!";
}
[/source]

[edit]
The code above is NOT what I typed.
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]
Yes, anything that uses the greater or lesser signs tend to break the code pad triviallly. As an example ANY C++ code using std::cout, std::cin, or templates.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.


Here's the code I entered to test, and I took a screenshot of what I got for the preview.

[source lang="cpp"]
#include <iostream>

// Empty class
class X
{
};

int main()
{
std::cout << "Hello world!";
}
[/source]

[edit]
The code above is NOT what I typed.


My other beef with the source tag is you can (pseduo-)edit its contents when you double click it:
64397381.png

So if you would like to copy a word from the source in order to look up the documentation for it or something, instead of highlighting the whole word when you double click the word, it'll enter "edit" mode and highlight the entire code for you. Awesome.

</iostream>
Oh right, the source box parses HTML, which I personally find a bit shocking since as Washu just pointed out the [lessthan] character is used often, especially in C.

The source box also parses BBCode, so something like an array index with the value i will turn all text after it into italics.


My other beef with the source tag is you can (pseduo-)edit its contents when you double click it:


Woah, never knew that...

Drew Sikora
Executive Producer
GameDev.net

This topic is closed to new replies.

Advertisement