Skip to main content
added 209 characters in body
Source Link
SirPython
  • 13.3k
  • 3
  • 38
  • 93

OOP(s)!

Right now, the meat of your code is two separate functions, just floating around and minding their own business.

It would be better practice to put these two functions into a utility class. That way, they both exist together and can be easily accessed from the same parent.

I recommend thatthink these methods should be static.

EDIT:

According to Jerry Coffin,

These don't look like member functions to me. In any case, a class that contains only static functions should usually be a namespace instead. – Jerry Coffin


Versatility

It is very, very uncommon for an HTML tag to just be a tag along with inner content; there are almost always attributes.

Right now, your code can only generate something like this:

 <foo>bar</foo>

What about this?

<foo spam="eggs">bar</foo>

To improve you code, I recommend create a class/struct that stores the attribute name and value, like this:

typedef struct {
    std::string name;
    std::string val;
} HTML Attribute

Then, your method could take an array of these and loop through them, adding them to the string each time.

OOP(s)!

Right now, the meat of your code is two separate functions, just floating around and minding their own business.

It would be better practice to put these two functions into a utility class. That way, they both exist together and can be easily accessed from the same parent.

I recommend that these methods be static.


Versatility

It is very, very uncommon for an HTML tag to just be a tag along with inner content; there are almost always attributes.

Right now, your code can only generate something like this:

 <foo>bar</foo>

What about this?

<foo spam="eggs">bar</foo>

To improve you code, I recommend create a class/struct that stores the attribute name and value, like this:

typedef struct {
    std::string name;
    std::string val;
} HTML Attribute

Then, your method could take an array of these and loop through them, adding them to the string each time.

OOP(s)!

Right now, the meat of your code is two separate functions, just floating around and minding their own business.

It would be better practice to put these two functions into a utility class. That way, they both exist together and can be easily accessed from the same parent.

I think these methods should be static.

EDIT:

According to Jerry Coffin,

These don't look like member functions to me. In any case, a class that contains only static functions should usually be a namespace instead. – Jerry Coffin


Versatility

It is very, very uncommon for an HTML tag to just be a tag along with inner content; there are almost always attributes.

Right now, your code can only generate something like this:

 <foo>bar</foo>

What about this?

<foo spam="eggs">bar</foo>

To improve you code, I recommend create a class/struct that stores the attribute name and value, like this:

typedef struct {
    std::string name;
    std::string val;
} HTML Attribute

Then, your method could take an array of these and loop through them, adding them to the string each time.

Source Link
SirPython
  • 13.3k
  • 3
  • 38
  • 93

OOP(s)!

Right now, the meat of your code is two separate functions, just floating around and minding their own business.

It would be better practice to put these two functions into a utility class. That way, they both exist together and can be easily accessed from the same parent.

I recommend that these methods be static.


Versatility

It is very, very uncommon for an HTML tag to just be a tag along with inner content; there are almost always attributes.

Right now, your code can only generate something like this:

 <foo>bar</foo>

What about this?

<foo spam="eggs">bar</foo>

To improve you code, I recommend create a class/struct that stores the attribute name and value, like this:

typedef struct {
    std::string name;
    std::string val;
} HTML Attribute

Then, your method could take an array of these and loop through them, adding them to the string each time.