« first day (2099 days earlier)      last day (2850 days later) » 

4:02 PM
 
While reading cpp core guidelines, I came across this

void lower(zstring s)
{
for (int i = 0; i < strlen(s); ++s) s[i] = tolower(s[i]);
}

What is wasted in the code?
 
@hello Time (potentially). Most compilers will generate code that calls strlen again every iteration of the loop, so you have an O(N*N) algorithm instead of O(N).
 
2016:07:15:09:04:44:607 TID:1D8C VAR_LOG: Processing Weight on: 30 30 30 30 38
2016:07:15:09:04:44:607 TID:1D8C VAR_LOG: Processed Weight: 80
2016:07:15:09:04:49:647 TID:3A10 VAR_LOG: Processing Weight on: 30 30 30 30 38
2016:07:15:09:04:49:647 TID:3A10 VAR_LOG: Processed Weight: 800
these both call the same function...
its const function
 
void lower(zstring s)
{
    auto len = strlen(s);
    for (int i = 0; i < len; ++s) s[i] = tolower(s[i]);
}
@hello This gives O(N).
 
@JerryCoffin oh.. gotcha. Thanks!
 
4:08 PM
@hello Oops--as it stands now, that's O(infinity). Need to increment i inside the loop.
 
@JerryCoffin O(N^2) actually, as strlen is reevaluated EVERY loop iteration
 
@Mgetz You have to follow the thread. I'd already told him his code gave O(N * N). The "this gives O(N)" was referring to the code in the immediately-preceding post (which does not re-evaluate strlen every iteration).
 
@JerryCoffin you can use the comma operator to put len inside the loop scope FTIW
 
@hello Note that this still traverses the string twice, for no particularly good reason. You'd usually want something more like: while (*s) { *s = toupper((unsigned char)*s); ++s; }
Oops--bad day. That should be tolower, of course.
@Mgetz You can, but it's still the wrong way to do, IMO. You usually wan to do the job without strlen at all (as shown above).
 
@JerryCoffin correct, but what you really want in most cases is to use a unicode aware strings library from the start.. so you can handle all the strange corner cases
 
4:18 PM
RUNS AWAY.
 
@hello Do note the cast to unsigned char there too. Without it, the code can crash as soon as you give it things like accented characters.
 
Changes some lines, change them back, recompile.... error is gone.
 
@Mgetz I'm not entirely convinced that I agree. Unicode certainly has some advantages, and I was once quite enthused about it--but not so much any more. It also often leads to an illusion of doing a lot more than you really have--dealing at all well with many languages requires a lot more than just using Unicode and changing how you manipulate strings.
 
@JerryCoffin yeah I ran into this in swift, it makes it near impossible to work on byte strings because it tries to be Unicode first and safe
 
4:38 PM
Lol I'm so ashamed of myself. I got irritated that a bug fix I implemented wasn't working (I only debugged at first, i didn't print out information). Turns out that for some reason while debugging the debugger was throwing me into the if statement, even though it didn't evaluate as true. Even posted a thread about it. D:
 
Ven
@Morwenn omg!1
i was gonna say "and you let us do all the hard work" but it was a single click away
 
@Jeff But at least you deleted your question about it. "If at first you don't succeed, destroy the evidence that you tried."
 
@JerryCoffin Oooh "short float"
 
@JerryCoffin Haha exactly, I must hide all evidence of my noobie mistake or risk the shame of people seeing it.
That really did throw me off though, I've never seen a debugger incorrectly evaluate a statement.
 
@Jeff Oh, we can't have that, now can we? You must be subjected to proper levels of mocking.
 
4:44 PM
@JerryCoffin Please no, have mercy, I'll never make the same mistake again D:
 
@Jeff Sure you will. We all do!
 
Nope nope, I can only make a mistake once (what a load of crap). lol
Is that logic okay in your opinion though? Like, clean and easy to read?
 
Answer: It's complicated. — Mysticial 12 secs ago
3
 
@Mysticial welldone
 
Complicated as in, hard to read and I should clean it up?
 
4:53 PM
so, how can this happen?
call the same functions in the system, with the same input... get different output
(different instances)
but same data
this is like dark mater Heisenberg magic to me...
 
Many ways. External influence (think environment, locale, versions, timings, accounts). If it's really identical, then UB is always there
> mater Heisenberg
 
@sehe its consistent across multiple machines at least,
 
That's my dominatrix
 
I've got a fix... but I want to understand...
 
@roscoe_casita huh. You said it's inconsistent to begin with. You mean, it's consistently inconsistent?
 
4:58 PM
Heisenberg fix... you get a fix, but you don't understand why it works.
yes @sehe
first call to the function works, all calls after fail
its atoi
 
Perhaps you should say useful things. And post on Stack Overflow
@roscoe_casita Ah. That's peanuts. Put it in a 5-10 line SSCCE. And put it on SO. That's what it's for: "I have this fix, but I don't understand it".
 
SSCCE?
 
I don't know how to abbreviate Google
 
@Jeff I think it's probably open to some improvement. I'd probably write something more like this: coliru.stacked-crooked.com/a/2a30e6f21b3baced
 
5:00 PM
@roscoe_casita short, self contained, compilable, correct example
 
@ThePhD That sinking feeling...
@Jeff I like to read "complete, compilable" - I dunno what is "official"
 
@sehe yeah that sounds better
that's probably what it is, if something were correct you wouldn't be posting for help
 
I was casting unsigned char to char and passing it into atoi
UB
fair enough explination, using std::stringstream conversions now
 
@JerryCoffin, thanks for showing me that, it looks wayyyyyy better than what i did.
 
5:16 PM
Hi.
 
Lo.
 
Mid.
 
Treble.
 
Bass.
 
Carp.
 
nwp
-1
Q: c++ : fix my code

tanmay_freakI came up with a code to calculate number of beads for the question on USACO training problem named 'beads'or also known as broken necklace. Anyways the function below is to calculate the continuous number of beads of 2 different color like 'rrwrrbbwbw'. The logic I came up with was by using brut...

at least there is honesty
---
I wonder if someone upvoted it so it doesn't go to -3 so people see it to close it
apparently the hidden --- feature is a lie
 
@nwp Nice. /cc @Borgleader
 
@nwp also interesting formatting style
using namespace std; int cal(string ring, string::iterator i){
string:: iterator l , r ;
int count;  for( i = ring.begin() ; i != ring.end() ; ++i )
 
wow, ok, found it @sehe
there was old memory hanging around
2016:07:15:10:34:06:787 TID:42A4 VAR_LOG: Read File Finish: 53 31 34 34 30 30 30 30 32 0D
2016:07:15:10:34:06:787 TID:427C VAR_LOG: Inside Convert English Weight String: 00002
2016:07:15:10:34:11:198 TID:42A4 VAR_LOG: Read File Finish: 53 31 34 34 30 30 30 30 32 0D
2016:07:15:10:34:11:198 TID:42A4 VAR_LOG: Inside Convert English Weight String: 000020
at least it makes sense now.
 
I shouldn't really pick at his code b/c i sorta suck myself but...
you'd think he'd atleast try to get the formatting correct?
 
5:47 PM
@roscoe_casita yeah. std::remove(first, last) doesn't physically remove memory
 
Not many interesting papers in the post-Oulu mailing.
 
Ven
@Morwenn any links?
 
@Ven There's one about matching types but I didn't read it yet.
For the general mailing link:
2 hours ago, by Jerry Coffin
@Morwenn For anybody who cares, a link: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/#mailing2016-07
 
Ven
@Morwenn it's basically C11's _Generic... but insane
> In this paper, generic (styled after _Generic from C11) is used as a convenience to identify the new construct in code.
they say it as well
 
Except C11 _Generic takes values, not types.
 
Ven
5:54 PM
that's why this one is insane
template <typename T>
constexpr auto array_size_v = inspect<T>(
  [std::array<<!T!>, <!(size_t)N!>>]: N, // typename (see next line) is implied
  [<!typename T!> [<!(auto)N!>]: N
);
ZEA BLUSH BLUSH
 
lolwut
403 Syntax Forbidden
 
@Ven Is it syntactic macros - but with the emphasis on "sin", not "tactics"?
 
Ven
@sehe Oh I'm sure deciphering the code is going to be harder than any tactical game I've played.
 
@Jeff can't possibly do formatting during input
 
Ven
remember kids, "Better kill yourself lest they kill you."
 
5:57 PM
@Ven Would you say it's... a taxing sin?
 
Ven
maybe a dancing queen
 
@sehe Can't tax when it isn't legal :(
> C++Next: lol, allocators are still half-assed.
 
@sehe true, i forgot just how hard it is to make sure stuff has the proper whitespacing, my apologies XD
 
Today my coworker asked another coworker "What do you develop on"?
The answer: "14"¹
Me, immediately: "Isn't that a bit young, though?"
¹ the context likely implied the Ubuntu LTS version
@Jeff It's only hard without abstraction.
 

« first day (2099 days earlier)      last day (2850 days later) »