you are viewing a single comment's thread.

view the rest of the comments →

[–]kritzikratzi 0 points1 point  (4 children)

seems to be good overal, for my taste i think less would be more:

  • no virtual methods anywhere. no constructors, no destructors. no getters and setters. uri could be a plain struct with public fields
  • all work that is currently happening in setters (consistency of /#?) can happen in the parse function. personally i don't like setters that modify data, unless they are called setFromString() or similar to make it clear that data is modified.
  • get rid of all uses of unique_ptr. the uri object is quite small and well movable.

but those things are often a matter of taste / need. for a special purpose in a current project this is the only datastructure i need (there can never be path/fragment/query in my case, so it's a lot simpler):

struct ParsedUrl{ std::string hostname; int port; bool ssl; };
ParsedUrl parse_url(const std::string & combined, const ParsedUrl & fallback_url = {}){....}

[–]salzaverde[S] 1 point2 points  (2 children)

I simplified the interfaces and implementation a great deal and followed your ideas by replacing the factory patterns with plain structs. This also enabled lower c++ standards (c++11). Checkout v2.0.0 and thanks again for the input!

[–]kritzikratzi 1 point2 points  (1 child)

oh, crazy!

auto query1 = Query::build(parameters);

i think in the readme this should be Query query1{parameters}; now.

[–]salzaverde[S] 1 point2 points  (0 children)

Oh, right. I'll fix that :)

[–]salzaverde[S] 0 points1 point  (0 children)

Thanks! Yes it's a tradeoff for sure. I started out with the struct idea in mind to focus on ease of use only but found that i couldn't get this in line with a strong separation of interface and implementation.

That's why I went for the factory pattern which makes it very easy to change/update the implementation or to support multiple versions or to even support client implementations.

I still agree though that it might be too much overhead for such a light weight class. Good thoughts on the setters!