In the screenshot it said x = *(++p) and iirc that is not the same as saying x = *(p++) or x = *(p += 1)
As in my example using ++p will return the new value after increment and p++ or p+=1 will return the value before the increment happens, and then increment the variable.
Or at least that is how I remember it working based on other languages.
I'm not sure what the * does, but I'm assuming it might be a pointer reference? I've never really learned how to code in c or c++ specifically. Though in other languages ( like PHP which is based on C ) there is a distinct difference between ++p and (p++ or p+= 1)
The last two behave the same. Though it has been years since I did a lot of coding. Which is why I asked.
I'll install the latest PHP runtime tonight and give it a try xD
But assuming it doesn't the context is p_ch = the bits above... the code declaring p_ch isn't shown but I'm guessing that the value here is actuality a pointer to a pointer so nothing illegal would be happening.
Lastly... C++ is really lacking in guarantees so you can assign a char to the first byte of an integer - C++ doesn't generally care what you do unless you go out of bounds.
The reason I'm casting to void* is just pure comedy.
That's not a real operator. You've put a space in "i--" and removed the space in "-- >". The statement is "while i-- is greater than zero". Inventing an unnecessary "goes to" operator just confuses beginners and adds something else to think about while debugging.
And yes I have seen beginners try to use <-- and --<. Just stop it.
The sheer number of people that do not expect a joke on this community... (Really, if you are trying to learn how to program pay attention to the one without the Humor on the name, not here.)
IDK, but if the reason is "to break stuff into multiple functions", then I'm not necessarily writing yet another single-use function just to avoid writing a comment, especially in time critical applications. Did that with a text parser that could get text formatting from a specifically written XML file, but mainly due to it being way less time critical, and had a lot of reused code via templates.
Like with everything, context matters. Sometimes it can indicate poorly structured control flow, other times inefficient loop nesting. But many times it is just somebody’s preference for guard clauses. As long as the intent is clear, there are no efficiency problems, and it is possible to reach the fewest branches necessary, I see no issues.
Indentation implies there's some control structure causing it. Too many control structures nested gets hard to mentally keep track of. 3 is arbitrary, but in general more indentation => harder to understand, which is bad.
It's important to remember that Linus is primarily writing about C code formatting. C doesn't have things that tend to create more deeply nested structures, such as a formal class syntax, or nested functions.
Going too deep is still bad--as zea notes, it's an indication of control structures run amok--but the exact number is dependent on the language and the context.
Honestly I don't mind the indentation since C isn't going to give us many ways to address this with as little code.
That said, with compilers that are good at inlining trivial functions, I really do appreciate the "it does what it says on the tin" approach to using functions on things like this. Even if they're only used once. Comments would help too.
The logic in these if statements is inscrutable on a cold read like this. To me, that's a maintenance risk; imagine seeing a snippet this size on a PR. Having functions that name what the hell is going on could only help.
Bought it the first day, and I expect them to take a long time before its ready. The game have been in development for many years and it looks and feels amazing, so i want it to take time!
This has come up in the past. I believe Mandarin has a short and quick word for this. English doesn't have the same cultural background so there's no quick name for it.
Compare this to writing out "MothersOrFathersBrotherOrSistersDaughterOrSon" instead of "cousin". In fact, my own language doesn't even have a word for "sibling", all we have is "brother or sister", despite being surrounded by languages that do have such a word.
I think Chinese and Korean culture share this concept, and I wouldn't be surprised if there were more Asian languages who did. Since a daughter joins her husband's family upon marriage, their children are considered belonging to the other family. I recently learner that apparently there's a saying in Korean that daughters always leave things at their mother's house when they get married so they have a reason to come back despite having left the family.
China, at least.
Lots of distinction between mother side and father side.
Grandma can be 老老 laolao (mother's mother) or 奶奶 nainai (father's mother), for example.
I've actually worked with a genuine UX/UI designer (not a mere Graphics Designer but their version of a Senior Developer-Designer/Technical-Architect).
Lets just say most developers aren't at all good at user interface design.
I would even go as far as saying most Graphics Designers aren't all that good at user interface design.
Certain that explains a lot the shit user interface design out there, same as the "quality" of most common Frameworks and Libraries out there (such as from the likes of Google) can be explained by them not actually having people with real world Technical Architect level or even Senior Designer-Developer experience overseeing the design of Frameworks and Libraries for 3rd party use.
Yes you should. I think most comments here are about products that have millions of users where it's actually worthwhile spending all that extra time and money to perfect things.
For most development, it isn't worthwhile and the best approach is to wing it, then return later to iterate, if need be.
The same goes for most craftsmanship, carpentry in particular. A great carpenter knows that no-one will see the details inside the walls or what's up on the attic. Only spend the extra time where it actually matters.
It triggers me immensely when people say "I could have made a better job than that" about construction work. Sure maybe with twice the budget and thrice the time.
Exactly. I'd also like to add, look at Google stuff their ui / ux is routinely horseshit. So don't tell me there are ui/ux gurus out there GIGAchading user interfaces.
A lot of this shit is trial and error and even then they still fuck it up.
Make it accessible, make it legible and then fine tune it after.
Many Designers are not good at knowing what their users need, because they don't have the resources, background or education to understand user behaviour.
I've used C but never C++. What does it mean for a variable's type to be int&? From when I've used it, & would be used to create a pointer to a variable, but the type of that pointer would be int*.
edit:
never mind, I looked it up. It's a "reference" instead of a pointer. Similar, but unlike a pointer it doesn't create a distinct variable in memory of its own.
In my experience, it's rare to see int& in day to day as a regular old lvalue... it essentially just allows you to alias a variable to another name. It's much more common to see them used in function parameters to leverage pass by reference. In C++ pointers usually aren't particularly useful compared to just passing things by reference since stack variables get auto-gc'd it's the preferred style of frameworks like Qt and is extremely easy to use.
never mind, I looked it up. It’s a “reference” instead of a pointer. Similar, but unlike a pointer it doesn’t create a distinct variable in memory of its own.
I'm almost sure it does create a distinct variable in memory. Internally it's still a pointer, specifically a const pointer (not to be confused with a pointer to a const value; it's the address that does not change). Think about it as a pointer that is only ever dereferenced and never used as a pointer. So yes, like the other commenter said, like an alias.
I don't think references are variables: you can't modify them, and AFAIR you can't have pointers to them, with the possible but unlikely exception of non-static member references.
An int& reference is just as much of a variable as int* const would be (a const pointer to a non-const int). "Variable" might be a misnomer here, but it takes just as much memory as any other pointer.
For references within a scope, you’re probably right. For references that cross scope boundaries (i.e. function parameters), they necessarily must consume memory (or a register). Passing a parameter to a function call consumes memory or a register by definition. If a function call is inlined, that means its instructions are copy-pasted to the call location so there’s no actual call in the compiled code.
Why have an async block spanning the whole function when you can mark the function as async? That's 1 less level of indentation. Also, this quite is unusable for rust. A single match statement inside a function inside an impl is already 4 levels of indentation.
A single match statement inside a function inside an impl is already 4 levels of indentation.
How about this?
The preferred way to ease multiple indentation levels in a switch statement is to align the switch and its subordinate case labels in the same column instead of double-indenting the case labels. E.g.:
switch (suffix) {
case 'G':
case 'g':
mem <<= 30;
break;
case 'M':
case 'm':
mem <<= 20;
break;
case 'K':
case 'k':
mem <<= 10;
/* fall through */
default:
break;
}
I had some luck applying this to match statements. My example:
let x = 5;
match x {
5 => foo(),
3 => bar(),
1 => match baz(x) {
Ok(_) => foo2(),
Err(e) => match maybe(e) {
Ok(_) => bar2(),
_ => panic!(),
}
}
_ => panic!(),
}
Is this acceptable, at least compared to the original switch statement idea?
i personally find this a lot less readable than the switch example. the case keywords at the start of the line quickly signify its meaning, unlike with => after the pattern. though i dont speak for everybody.
the problem is that, while skimming the start of each lines, nothing about 'G' | 'g' tells me that its a branch. i need to spend more time parsing it. mind you, this may simply be a problem with rust's syntax, not just ur formatting.
I mean, I use formatters everywhere I can exactly so I don’t have to think about code style. I’ll take a full code base that’s consistent in a style I dislike, over having another subjective debate about which style is prettier or easier to read, any day. So whatever cargo fmt spits out is exactly what I’ll prefer, regardless of what it looks like, if only for mere consistency.
Well, of course you can have few indent levels by just not indenting, I don't think the readability loss is worth it though. If I had give up some indentation, I'd probably not indent the impl {} blocks.
actually, i would like to counter this. Developers often times put together shitty UIs that are hard to navigate (mostly because UI design is bad and we've been living with floating WMs for the past 30 years so nobody knows any fucking better for some godforsaken reason)
But it's no fault of the user for using a shitty interface if it was designed to be used in that manner, by the person who built it. This is why so many people like CLI, it's impossible to fuck up. You can use it wrong as a user, but that's because it has specific syntaxing. It's designed to only be used in that one manner, where as most graphical applications are designed to be "generally applicable" for some reason, and then when a user uses it in a "generally applicable" manner, somehow that's now the wrong way to use it?
floating WMs are intuitive, but the problem is that they're an incredibly mediocre solution, and the way that problems are often solved around one, is just entirely asinine. Let's build ten different ways to do the same thing, now we have 10x the code to build and maintain, and it's 10x more confusing to the end user who probably won't know about half of them, because 90% of our documentation is redundant!
Tiling WMs have significantly less issues with this, because they often have a very strict set of management rules, and only those. Nothing more.
People screw up CLI's all the time (looking at you Google Cloud). They (used to) insist on using my installed python which automatically upgrades and breaks the CLI. Good job python. Good job Gcloud.
Programmer Humor
Top
This magazine is not receiving updates (last activity 54 day(s) ago).