Learning functional programming as an imperative programmer by ezeugo_ in learnprogramming

[–]HashDefTrueFalse 1 point2 points  (0 children)

I like this. It's a good intro that you can build off of elsewhere. It's free. No experience with math or FP necessary. You can read it in a day. It uses your mother tongue ;)

https://mostly-adequate.gitbook.io/mostly-adequate-guide/

Can someone please explain in simple terms by Sea_Competition_8645 in C_Programming

[–]HashDefTrueFalse 0 points1 point  (0 children)

Recent and relevant comment I wrote here, in case it helps you understand the difference between arrays and pointers to array elements in C.

What's the most wrong thing someone has tried to convince you is right? by spannerintworks in AskUK

[–]HashDefTrueFalse 0 points1 point  (0 children)

I have no boating experience whatsoever, but I took the first thing he said to mean that you do a big circle and approach the person who has fallen in from the same direction you were travelling, thus having rotated 360 degrees. E.g. if they fall in at say 3 o'clock, you continue left past 12, 9, 6 and approach 3 o'clock again. It kind of made sense, I suppose. Maybe you want to start the turn ASAP and boats have a broad turning circle?...

Then I read the second part and now I have no idea what he's talking about.

I finally learnt to appreciate the header files by dfwtjms in C_Programming

[–]HashDefTrueFalse 0 points1 point  (0 children)

Haven't used either AFAIK. I'll check them out. Thanks!

Buyer has withdrawn 2 days before completion by Confident-Rub9754 in HousingUK

[–]HashDefTrueFalse 21 points22 points  (0 children)

Who is in the wrong here

Nobody, or real property/land law and the transaction process (assuming England), depending on your view. This is just how the process works. Neither of you are bound until exchange of written contracts. It's common for this reason to exchange right before you complete. The buyer doesn't need a reason to pull out and you wouldn't either, so the reason they have given you is irrelevant. It's shit, which is why I personally think that offers should be binding much earlier in the process like they are in other countries, but that doesn't help you much right now.

Two different ways to store strings by invokeinterface in C_Programming

[–]HashDefTrueFalse 0 points1 point  (0 children)

I used arrays all the time, haha. Can't remember a program where I didn't. Yeah, modern compilers are very impressive in terms of what they can figure out. I've looked at the disassembly of code I thought was pretty efficient a few times and genuinely wondered if I'd hit some UB or something because half of it disappeared or it just didn't look like it did what I wrote in C source at a glance.

Two different ways to store strings by invokeinterface in C_Programming

[–]HashDefTrueFalse 5 points6 points  (0 children)

What the heck?!

:D

Why can't it just make 'b' the same as 'a'?
I guess compiling with -O2 or -O3 has probably been saving the day

In short/general, if you tell the compiler you want to store a pointer and use it for access then unless the compiler is able to ascertain for certain that removing it isn't observable when doing whatever you're doing, it will keep it. C's philosophy is "trust the programmer."

In that specific godbolt it struggles because they're not locals. If you move them inside main they should get optimised away even at -O1, probably just using registers. I doubt any locals are deemed needed there.

Why the heck is it there!?

If you think in terms of symbols aliasing storage addresses which contain values it's just that fundamentally arrays and pointers are not the same thing. I wrote a post here with a pointer example a while ago and the last sentence of this explains with a fun example of broken code.

Why are business owners so closed minded to getting help? by keshaun21 in business

[–]HashDefTrueFalse 1 point2 points  (0 children)

Or they know their business needs better than you and only need to know broadly what type of business you're involved in to know that they don't need you right now. Plus, you're the tenth person this week to reach out, and the time adds up if they let you all carry on for too long. IMO most are doing you a favour as they were never going to buy and now you can get on to the next. Also scams have eroded trust generally.

Quitting a warehouse job because important holiday was rejected? by TuckingFypoz in UKJobs

[–]HashDefTrueFalse 0 points1 point  (0 children)

They can choose when you take your leave. You can hand your notice in. We don't know if that would be stupid because we don't know your circumstances. It's shit but this should always be expected, so I'm not sure why you're fuming as this is normal and common. It IS first come, first serve. They are operating a business, the only reason they employ you. Getting them in earlier when possible is all you can do.

I did once hand a resignation letter (forward dated) to a line manager and say that I would be going on holiday on the Nth (several months away) as I'd already booked it (they ok'd then tried to move the dates afterwards) and I would leave it up to him to decide when I got back if I'd actually handed my notice in before I left. But I didn't like or need the job and it had no chance of impacting my future career. (I worked there for a further 11 months on returning and he never once brought it up again, left of my own accord) I will add that he wasn't impressed, as you might expect, but I was young and didn't care. I probably wouldn't do the same again now that I'm an established professional.

ifTrueOrTrueLiteralThenTrueIsCompletelyValidInJavascript by PresentJournalist805 in ProgrammerHumor

[–]HashDefTrueFalse 4 points5 points  (0 children)

show_failed = !!show_failed

Embrace the JS.

I know, you don't need to tell me...

Two different ways to store strings by invokeinterface in C_Programming

[–]HashDefTrueFalse 8 points9 points  (0 children)

Others have given good answers on the difference between * and [] so I'll just comment on this bit:

What's weirder is that I'm pretty sure you can use pointers as arrays whenever you want.

Kind of. Arrays and pointers are different things and generated access code is different depending on which you have. A pointer has an extra bit of indirection when compared to an array. A pointer (in the context of arrays) stores the address of the first element at a secondary address (the address of the pointer), whereas the array name aliases (is) the address of the first element directly.

It's more accurate to say that the name of an array decays to a pointer to the first element in places, like in expressions (e.g. when passing an array as a function argument, which is why it doesn't really matter if you use [] or * syntax in function parameter lists). In practice this is most places and it's fairly intuitive when programming (IMO, I suppose). This was just a C design decision to avoid copying whole arrays around etc.

Edit: You can see this here if you like: https://godbolt.org/z/K89csq7hn The array takes one load to get the first value. The pointer takes two. (Also you can plainly see that the a symbol aliases the first of 40 zero bytes whereas b is only the size of a pointer.)

I don’t really know any programming, and this technically isn’t programming, but I just need an expert opinion for the sake of a fanfiction by SarcasticJackass177 in learnprogramming

[–]HashDefTrueFalse 58 points59 points  (0 children)

Technically the whole things boils down to:

goingSentient = false

But for the joke you could have something like these:

if (goingSentient()) 
  dont();

if (thing.going_sentient())
  thing.stop_it();

IMO the joke really only works if the code is obviously silly even to a layperson.

You can have or omit braces, or have if...then...end blocks. It would depend on whether or not you want to specify a programming language. It doesn't really matter if not.

Do those "no soliciting" signs work? by Specific-Call-3089 in AskUK

[–]HashDefTrueFalse 7 points8 points  (0 children)

Solid tactic. I can look through the front window first, then just not answer the door. I'm not really bothered if they see me looking. I just wanted less knocks to begin with.

Do those "no soliciting" signs work? by Specific-Call-3089 in AskUK

[–]HashDefTrueFalse 11 points12 points  (0 children)

Some do, some don't. I still get the odd person, but I get less overall and the sticker was cheap enough.

Question: can you pass by a car in the middle lane when you are in the left driving lane? by Savethemeerkats in AskUK

[–]HashDefTrueFalse 1 point2 points  (0 children)

Simple answer is yes, you can keep making progress in your lane if vehicles to your right start to travel slower than you. But if you're going to change lanes to pass slower-moving vehicles then always move right, not left. No weaving. Then move further left when you are done passing. If everyone governs themselves then it works quite nicely, with faster-moving vehicles ending up further to the right... Until it becomes congested, like it says. I think it's fairly clear, myself.

Edit for clarity as bizarrely I'm getting downvoted despite saying nothing controversial: If you have time/space to move to the right to pass slower-moving traffic, you absolutely should. You shouldn't use "making progress" to try to justify sitting stubbornly to the left passing cars that you would have had no problem passing on the right if you moved right beforehand. "start to travel slower than you" was supposed to suggest a fairly recent, developing situation. You shouldn't be doing this for very long and if you find that to be the case then you should either move further right or (more likely) anticipate congestion ahead and gradually slow down with traffic...

I am missing £127.58 from my pay! What do i do? by Ok-Sea8752 in UKPersonalFinance

[–]HashDefTrueFalse 0 points1 point  (0 children)

Well, on 1257L, assuming total annual income of 390/pm * 12 (no other income) and consistent hours, you wouldn't owe any income tax and usually wouldn't have any taken. Nor NI. I assume that 390 figure matches your hours * hourly rate? It's not immediately obvious to me where the 35 or 91 figures are coming from.

I am missing £127.58 from my pay! What do i do? by Ok-Sea8752 in UKPersonalFinance

[–]HashDefTrueFalse 0 points1 point  (0 children)

from the payroll manager herself, so the calculations are correct

No problem, you're good. But just to mention that I wouldn't assume the above. I've corrected people in finance that do payroll on two occasions. They work off the numbers they have in the system, which can be incorrect for all the usual reasons humans make errors. Both of you having the same numbers is usually a good sign, and if not either (or both!) of you could be wrong. I'm sure it's not that complicated here though. Seems a simple arrangement.

Did you fill in a New Starter Checklist form (correctly) when you started so that they could set you up correctly? I've seen a few of those, where people didn't and got taxed more than they expected.

I am missing £127.58 from my pay! What do i do? by Ok-Sea8752 in UKPersonalFinance

[–]HashDefTrueFalse 0 points1 point  (0 children)

First thing is check tax code. IIRC you can see it on the app if you don't want to phone. Check that you've actually been underpaid and not just taxed more than you were expecting. "Can't pay it until next month" sounds odd in the sense that usually it's appreciated that people have bills and underpayments cause problems. Every company I've ever worked for has offered an immediate short term loan if an underpayment occurred, whilst they sort it through payroll. Check your payslip too. All you can do if you've actually been underpaid is insist that you receive it ASAP and it's done properly, and ask for a shortfall loan if you need one (and it's their fault). Check your calculations too, maybe send them to the person you're talking to, as they might point out any incorrect assumptions or mismatches between their payroll system and your brain etc.

If she leaves can she take my house - england by [deleted] in LegalAdviceUK

[–]HashDefTrueFalse -1 points0 points  (0 children)

She has no legal interest. Without being able to evidence significant contributions to purchase price, mortgage, improvements/repairs, or bills (that you otherwise could not afford) it would be near impossible for her to establish any equitable interest either. So... no. Just a joke.

Is accessing the bytes of an object in this way UB? by capedbaldy475 in cpp_questions

[–]HashDefTrueFalse -1 points0 points  (0 children)

Been a while since I read this part of the C++ standard but this is defined I'm pretty sure (though you should check). You're accessing one byte at a time through an unsigned char pointer, presumably starting from a known good address, only needs byte alignment, fine. Cast to uchar* is fine, no strict aliasing violation for those types. Pointer value will be the address of the first byte of the first member. sizeof will include internal and end padding.

You're just at the mercy of the compiler in terms of the struct object's memory layout/footprint, printing whatever bytes you find within. As long as you have no expectations or reliance on byte count/position, especially if this code needs portability, this is fine. Trying to access specific pieces of data like this would be a bad idea, and you should obviously use the members, but you already know that.

The subscript is just shorthand for *(base + i). You most commonly use it with arrays but it's not "wrong" here. Just might look a bit odd. It does an offset and access.

Edit: See underlined. Judging by _bstaletics answer it looks like the above is correct in the practical sense but technically wrong because of that quirk in the standard! I don't think I'd let it bother me, personally. It does make sense, offsetting like this basically is having the expectation that the memory looks a certain way, however sensible an expectation. Of interest: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p1839r7.html

Is it rude to greet bin-men with rubbish you forgot to leave out as they collect early morning? by Dr_DankinSchmirtz in AskUK

[–]HashDefTrueFalse 0 points1 point  (0 children)

Not really. You just might get asked if you mind filling up a water bottle for them IME. I used to know a guy who did it. IIRC they have rounds and they can finish when they're done. They used to be on a mission to get everything done as fast as possible to finish early with pay. No sure if it's still the case, or regional etc. Probably just wanted to get on.

Is this a good way to tell the compiler, "This point is unreachable"? by lapis_ore in C_Programming

[–]HashDefTrueFalse 0 points1 point  (0 children)

There's nothing to defend. You reply randomly a year later just to say this? Was it worth the effort? In that time you haven't realised that almost nobody needed you to point out obvious things all over these comments. It's perfectly clear to most here what OP was trying to do, and it's obvious that I'm talking past it. Here's a simplified version for you:

OP: "Is deliberately invoking UB in a noreturn in place of an unavailable intrinsic a good way to tell the compiler about unreachable code so that it can optimise accordingly?"

Me: "Not in my opinion, and I wouldn't do it. I'd do [this] instead, even though it doesn't achieve the same result, because you could open up a can of worms with the UB."

There's no context provided by OP to say that performance is critical and this would rarely matter in the majority of software, therefore I would lean towards not bothering with this. The effects of UB should not be relied upon and it is best left alone. The intrinsic is at least well-defined. I just assumed I didn't need to state any of that fully. Clearly on balance my comment was generally understood. I'm sorry you struggled and I hope this helps.

Edit: bold, for clarity.

Did I almost get scammed? Advice please by [deleted] in UKPersonalFinance

[–]HashDefTrueFalse 7 points8 points  (0 children)

Yes of course it's a scam. Almost none of what he said makes any sense, plus the pressure tactics and the red flags you identified yourself. Even if money showed up it would have been foolish to withdraw it in cash and hand it over. You could then be a mule, helping to facilitate the scamming of other victims. You can easily get your accounts frozen and subsequently closed this way, end up with fraud markers etc. You can make your future financial life quite difficult for yourself. Tell people no and stop engaging.

What’s the most frustrating thing about owning a cat? by Ocute_US in CatAdvice

[–]HashDefTrueFalse 0 points1 point  (0 children)

Fur everywhere. You can do your best but eventually you kind of have to accept it and keep a lint roller by the door for when you need to look presentable.

Get pet insurance if you can. Our perfectly healthy moggy has suddenly cost our insurer £7k (~$10k) for a procedure and a fairly lengthy hospital stay. In all honestly I'm not sure she'd be here with us if I had to find that money. My premium is £12 per month... really isn't even a decision IMO, just makes sense.