Skip to main content
GameDev.net gamedev.net
🔒 Locked

How knackered is your code paste

Started by Washu Feb 17, 2012 at 4:55 AM 28 replies 6.6k views
Original Post
Washu
Washu
So, I was posting a reply to a journal when it produced this:


Lexing took: 66ms
Parsing took: 0ms
Grammar
MetaEntities
Vector
Members
Member
real
X
Member
real
Y
Member
real
Z
Member
dot
ParamTypeSpec
Vector
Vector
float
entrypoint
Parameters

[/quote]
Now, here's the thing: If you go to edit you'll see that this actually only has FOUR space indents. Yet somehow that indent became EIGHT spaces...CONDITIONALLY. The actual reply is here, and the first indent WAS originally only four spaces, but after I edited it for quoting in this thread (without saving changes) it changed it to EIGHT spaces as well.

Now, we're a software development (with a focus on game development) website. So how hard is it for us to come up with a decent CODE/SOURCE box that actually, you know, works. By works I mean: When you paste code into it doesn't randomly remove or insert new spaces, newlines, and the color coding doesn't magically stay when you go to raw mode. Oh... and half your source doesn't magically vanish every time you click the "Raw" toggle switch on the WYSIWYG editor for posts.

Thoughts?
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.
Cornstalks
Cornstalks
I've already posted a gripe of mine with the editor. It also drives me nuts when someone copies and pastes some code, but the editor tries to preserve its rich text formatting, and then you end up with a post like this.
Washu
Washu
Oh yes, I've taken to pasting in notepad, then copying from there, THEN pasting to the forums to make sure visual studio formatting doesn't end up getting pasted. Interestingly though, it only happens SOME of the time.
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.
swiftcoder
swiftcoder

Oh yes, I've taken to pasting in notepad, then copying from there, THEN pasting to the forums to make sure visual studio formatting doesn't end up getting pasted. Interestingly though, it only happens SOME of the time.

It happens enough that I just instinctively toggle to 'raw' mode when pasting source. Mind you, I have to do the same for WordPress' syntax colouring plugin, so I guess it doesn't bother me all that much.
Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]
Sirisian
Sirisian
yeah it's a pain. Same here. Pasted some code earlier and it garbled it so I pasted in notepad then into their editor. Also having both [ code] and [ source] tags is fun.
rip-off
rip-off
I find Chrome's "paste as plain text" alleviates this to some degree. It is still annoying if you forget, and up to recently my Linux install of Chrome didn't have this feature.

I also find it annoying that copying and pasting text from someone else's post is in a different font to the message builder.
Cornstalks
Cornstalks
Yeah, what's up with source tags? I can't figure out how to specify a language so that there's syntax highlighting.

And yes to what SteveDeFacto said about uptime: it's been a lot better lately!
Matt328
Matt328
I had a hell of a time with it with a post the other day, if I put the lang="cpp" part in the source tag, it would chew it all up. Trying to edit the post to fix it just seemed to make it even worse. Finally I discovered that without lang="cpp" it at least put it in a code box with line numbers. I tried with both Chrome and Firefox, and had varying degrees of problems with each. Given that posting code is pretty common on this site, I hope they get it fixed ASAP.
Washu
Washu
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.
Gaiiden
Gaiiden
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
swiftcoder
swiftcoder

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]
fastcall22
fastcall22
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:
[/quote]
Washu
Washu

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:

[/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.
Cornstalks
Cornstalks

[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

// Empty class
class X
{
};

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

[edit]
The code above is NOT what I typed.
Washu
Washu
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.
fastcall22
fastcall22

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

[source lang="cpp"]
#include

// 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.

Gaiiden
Gaiiden
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.