Unpopular opinion: C++ `auto` should be almost always avoided. The only thing it gives is code that is harder to read, maintain and debug.
-
-
Vastauksena käyttäjälle @savage309
C++ ‘auto’ can make code _much_ easier for a human to read, esp for shared pointers, for each loops, etc which can become cluttered with template and const jargon. But it can also make code _harder_ to read if used constantly, or when type matters. As Obi-Wan says:pic.twitter.com/5JBMDapTev
0 vastausta 1 uudelleentwiittaus 23 tykkäystä -
Tämä twiitti ei ole saatavilla.
-
Writing text is rarely the bottleneck imho. And sure templates can be verbose, but I usually typedef them anyways. Then again, I rarely use templates so there’s that ofc...
1 vastaus 0 uudelleentwiittausta 2 tykkäystä -
Vastauksena käyttäjille @mwesterdahl76, @MenaceInc ja
You rarely use containers? Like vector and map?
1 vastaus 0 uudelleentwiittausta 0 tykkäystä -
Vastauksena käyttäjille @steverockan, @MenaceInc ja
I (we) use C-like C++. We have a few containers, like Array<> and HashTable<>. We close to never need to iterate over a table, we get the value pointer directly, so no template there. And for arrays, we use regular for loops with indices to access values. Or we just use C arrays.
1 vastaus 0 uudelleentwiittausta 1 tykkäys -
Vastauksena käyttäjille @mwesterdahl76, @steverockan ja
So perhaps a clarification is that I rarely have to deal with "template-ism", and writing long iterator types.
1 vastaus 0 uudelleentwiittausta 1 tykkäys -
Vastauksena käyttäjille @mwesterdahl76, @MenaceInc ja
Hmm can you elaborate on your hashmap iteration policy?
1 vastaus 0 uudelleentwiittausta 0 tykkäystä -
Vastauksena käyttäjille @steverockan, @MenaceInc ja
The class looks mostly like this (minus the iterator helper): https://github.com/JCash/containers/blob/master/src/jc/hashtable.h … There _is_ an HashTable::Iterate(fn_ptr, ctx) which maps a function onto each element. Mostly though, we just get items from the table.
1 vastaus 0 uudelleentwiittausta 2 tykkäystä -
Vastauksena käyttäjille @mwesterdahl76, @steverockan ja
I don't use templates and never need to iterate over a hash table. Haven't used auto in at least three years. Don't see any reason to use it. Makes code less understandable.
1 vastaus 0 uudelleentwiittausta 1 tykkäys
Counterpoint: Templates can be a good way to flatten branchy code when performance is critical. You could of course use preproc macros to emit multiple versions of a function, but why, when the language will do it for you?
Lataaminen näyttää kestävän hetken.
Twitter saattaa olla ruuhkautunut tai ongelma on muuten hetkellinen. Yritä uudelleen tai käy Twitterin tilasivulla saadaksesi lisätietoja.