Replies: 17 comments
-
Makes sense, of course. The requirement is c++17 so, |
Beta Was this translation helpful? Give feedback.
-
I was thinking that if concepts are not available, enable_ifs would still be better than static_asserts, because with them the IDE catches the errors before compilation. True, the error messages will be not so clean as with static_asserts when compiled, but reading the enable_if conditions is fairly straightforward. Who do you think is the current and future audience for the library? Would they benefit more from IDE support or somewhat cleaner compilation messages? As for making a PR myself, I may give it a try, but I cannot promise as I have other things I'm trying to focus on. Do you perhaps have any guidance on contributing to the library? For example, a document that describes its structure and components. That would make it easier to identify these functions where adding compile time checks would be useful. |
Beta Was this translation helpful? Give feedback.
-
In due time, when c++20 becomes more commonplace, my preference is concept (to be honest I am resisting the temptation now!). In the meantime I'd prefer static_assert over enable_if. One downside with enable_if is that it tends to clutter the API with ugly code. I have no idea if current and future audiences are IDE users. I don't think there's a way to know. Alas, there are no internal documents yet about the structure and components. For simple things like this, on 'maintenance' mode, I just plow through the code and check things that can be improved. I suppose that's what you did that landed you into the |
Beta Was this translation helpful? Give feedback.
-
Not a problem at all. We're all busy. That said, incremental PRs (say, a function here and there) would be fine too... On the other hand, a "no I'm busy" would be fine too. I just added this in my todo list anyway, and I'll get to it eventually when I go into maintenance mode. |
Beta Was this translation helpful? Give feedback.
-
Yeah, I agree that concepts are not a good choice for now, they would exclude too many users. I tried them however, and they are real awesome, so it got me excited. I think for now static_asserts would be nice, perhaps they can be even marked with a TODO comment and then they can be easily replaced by concepts when they become more available. Well, I landed in the It fails at template <typename... E>
inline auto htile(E&&... elements)
{
using composite = array_composite<sizeof...(elements), htile_element>;
using container = typename composite::container_type;
composite r{};
r = container{{ share(std::forward<E>(elements))... }};
return r;
} While your code is undoubtedly clean and neat, the generic and templated structure makes both static (i.e. looking at code) and dynamic (i.e. looking at runtime callstacks) understanding of its workings challanging. Perhaps these would help both users and developers:
Like for me right now, I would need an effective way to identify all/most functions that are used to declaratively describe the user interface, and then deciphering and patching in compile time checks is a fairly straightforward process. Also, a general understanding of the concepts makes it easier to find the right constraints for the static_asserts. Plowing through code is fairly difficult without familiarity with the library. |
Beta Was this translation helpful? Give feedback.
-
Splendid comments! Replies below...
Yeah, I've been following concepts since 0x as it has undergone significant changes, from different camps. The first one "C++0x Concepts," was a lot more powerful, actually. Alas, it did not win the battle.
[snips] Yeah, I understand what you mean. There will be more of this, I am sure. These are the things that are in my "todo" list that I act on as part of maintenance.
Understood. My main goal now is to have a complete set of docs. It's kinda tricky though as the code is also undergoing evolution.
Aren't those a matter of documentation? I'm not sure I am inclined to go into a 'bike-shed' discussion on names though.
TBH, I dislike doxygen. I haven't seen a usable doxygen generated docs for a generic, modern c++ library. If you know one, I'd like to see it. I'm open to be convinced.
Absolutely! As stated in the main page: "Documentation is work in progress." I work on it regularly, at least a few hours a week. Well written documentation, like code, is a craft, takes time.
Absolutely!
Interesting idea. Noted! I'll ponder on this. This might also solve some class vs. (factory)function dilemma. E.g. class button_element vs. button function.
Yes, I understand. I'll see if I can get something up in the coming days. If you liked the layouts docs, that's my idea of what documentation should look like. It takes time to craft such documentation, but I think it is very much worth it in the end. |
Beta Was this translation helpful? Give feedback.
-
I totally agree, writing quality documentation is neither easy nor fast, especially with evolving code.
Yes, definitely. The layouts doc was very helpful, and a similar one for controls would be much appreciated.
Good question. Variable names are a form of documentation themselves, so the more specific they are, the less "real" documentation you have to write and the less people have to look at the documentation. There is much talk about fully "self-documenting code", but I'm not sure if that exists in real life, or if it's even desirable. Nevertheless, I think a little more verbosity pays off in the end: regarding the
SFML is not really generic, but I think its documentation is pretty good. Then there is also Eigen, which is a fully templated library. The docs of LEMON also proved pretty useful to me. I think that doxygen comments have their place: they are something between variable names and user guides. A small extra piece of information attached to a variable that describes what the variable name could not capture. Doxygen comments won't help you understand the general use of the library, but can help clear up its individual pieces. Also, it's very handy that you have the docs right next to the code, without searching for them or leaving the IDE. As an example, here, people know they want shear, and they will find the shear transform. However, the variable names really only make sense with the extra documentation, because they are hard to unambiguously describe in just 2-3 words. /// <summary> Creates a shear matrix. </summary>
/// <param name="slope"> Strength of the shear. </param>
/// <param name="principalAxis"> Points are moved along this axis. </param>
/// <param name="modulatorAxis"> The displacement of points is proportional to this coordinate's value. </param>
/// <remarks> The formula for displacement along the pricipal axis is
/// <paramref name="slope"/>*pos[<paramref name="modulatorAxis"/>]. </remarks>
template <class T>
auto Shear(T slope, int principalAxis, int modulatorAxis) {
return ShearBuilder(slope, principalAxis, modulatorAxis);
} I used to dislike doxygen, too, but I kinda learned to appreciate it. I prefer the C#-style XML comments though, but doxygen can handle those as well. |
Beta Was this translation helpful? Give feedback.
-
I prefer *_type than *_t, although granted, _t is quite common, esp. in std. In this particular example, I'm probably OK with I agree with your reasoning though. Moreover, there are other factors at play too, such as consistency. I'm pretty sure I haven't paid enough attention to naming yet that I'm certain I've violated some. Naming too is not easy and many times, I get into that state where I say to myself: "this will do for now, I need to finish". That state of naming things is often at odds with the side of your brain involved with coding. Here's what I can do: How about starting with a set of naming guidelines (that includes the namespace suggestions)?
[snips] I'm not ready to go there yet. I guess I am too biased. Take Eigen, for example. What makes it good IMO is the proper documentation before the "reference" starting with Class List. But that documentation proper need not be in doxygen at all. I took out a random item in the Class List and I get this: My instant reaction is... Gak! |
Beta Was this translation helpful? Give feedback.
-
This one is usable though: |
Beta Was this translation helpful? Give feedback.
-
But I am still unsure. If you look at the layout docs, (and some of my Boost projects, e.g. Fusion), you will notice the style based on concepts, expressions and expression semantics, instead of function signatures. Here's an example in Fusion: https://www.boost.org/doc/libs/1_73_0/libs/fusion/doc/html/fusion/container/vector.html This style of documentation is not possible using doxygen. That is the style of documentation I will be aiming for, when the API stabilizes. For now, I am starting with generic concepts. |
Beta Was this translation helpful? Give feedback.
-
I think consistency is what matters here, otherwise both work perfectly fine.
Fortunately, these days, there are great refactoring tools, so renaming a not-so-perfect variable is easy. A weaker variable name only gets problematic when the name is in the public interface, because changing it would break users' code. I often just rename things when I'm reading or modifying existing code, because the right name does not always pop into my mind right away. I think this kind of renaming is an important part of maintenance and refactoring, so I was really only trying to provide some feedback and give a reminder.
That's a very good idea! I really miss having a For one of my projects I made a short table for names based on the options in ReSharper. As you said, however, the content of the variable names is very subjective and dependent on context, so I don't think much more than "be descriptive" can be said. Of course, some rules like "always suffix exceptions with |
Beta Was this translation helpful? Give feedback.
-
Naming style is simple to begin with: I just use the stl/boost naming scheme: CamelCase on template type parameters and concepts, lower_plus_underscore everywhere else, PREFIX_UPPER_UNDERSCORE on preprocessor names, where PREFIX is the main namespace, e.g. this case CYCFI. I'm with you: consistency is the most important factor here, so *_type is my preference. I added the 'naming guidelines' in my todo list. I'll get to it when I am on documentation mode. |
Beta Was this translation helpful? Give feedback.
-
That looks like something you could do with Jekyll/markdown, so it would be part of the website (and also readable offline from the md source as well). |
Beta Was this translation helpful? Give feedback.
-
I am already using Jekyll/markdown. Example: http://cycfi.github.io/elements/layout |
Beta Was this translation helpful? Give feedback.
-
Ah OK, I thought you were searching for another solution specific for API documentation :D |
Beta Was this translation helpful? Give feedback.
-
I really like this idea. There are cases of many name clashes that are differentiated only by overloading (button factories). I'm also for the assertions. Elements has some functions that expect certain inputs ( |
Beta Was this translation helpful? Give feedback.
-
My thought after just flying over the comments... |
Beta Was this translation helpful? Give feedback.
-
Just from a user perspective, the compiler errors were pretty arcane when I did not provide the right parameters to
htile
.htile
implicitly requires allE&& elements
to be derived fromclass element
.This is the general definition for these functions:
It would be possible to add either
So I'm just throwing this idea in that it may be useful to enforce these conditions more explicitly in the interfaces.
Beta Was this translation helpful? Give feedback.
All reactions