/dpt/ - Daily Programming Thread

Lucky F5 edition

Attached: 1212072927883.jpg (1280x720, 157K)

Other urls found in this thread:

en.wikipedia.org/wiki/John_Smith
man7.org/linux/man-pages/man3/pthread_cancel.3.html
warosu.org/g/
youtube.com/watch?v=j9tlJAqMV7U
python.org/doc/
twitter.com/SFWRedditImages

Re-asking.

Attached: 1566113620835.jpg (640x896, 401K)

The answer to every "why doesn't C have X" question is: C is a 47yo legacy language that you should feel bad for still using.

you paid for them. you should now do them.
protip: get your books from library genesis and then pay for digital copies if they really helped you.

Attached: 1565997191533.jpg (1920x1984, 1.69M)

Every C compiler now is made in C++.
The ISO Committee for C is nearly all the same people on the C++ committee now (which mind you is why they won't add features to C).
Rust and C++ have effectively deprecated C at this point
MIRSA C++ replaces C in embedded and critical systems
C2X has made virtually no progress still

I'm sure there's easily $100 worth of value in 8 Udemy courses. Whether or not you get $100 worth out of it is going to be up to you.

The semantics of C++ references are questionable at best. Pointers work fine and are obvious in their behaviour.

>tfw my email has numbers in it because my name is too common

Attached: sadrenge.png (691x720, 809K)

Abandon this thread!
Faggot OP can't even use proper format.

fuck off autist

Is there an equivalent of gitolite for subversion?

>tfw people see numbers in emails as unprofessional
Enjoy having your application chucked in the bin.

A domain costs like $10 and you can get good email hosting for less than $5/mo.

My name is "John Smith" tier. I can't even get a unique name on tutanota.

Yeah I'm thinking about it.

Anonymous can't be that common a name

>tfw your name is unique across the internet

No

I'll only answer if you post more cute girls with big anime titties.

Noise generator + viewer. Funny how you can draw on and capture any program window without any issue.
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;

class Program {
[DllImport("user32.dll")] static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")] static extern bool GetWindowRect(IntPtr hWnd, out Rect lpRect);

[StructLayout(LayoutKind.Sequential)]
struct Rect { public int Left, Top, Right, Bottom; }
static void Main() {
var hWnd = GetForegroundWindow();
GetWindowRect(hWnd, out Rect r);

using var g = Graphics.FromHwnd(hWnd);
using var bmp = new Bitmap(r.Right - r.Left, r.Bottom - r.Top);

var rndData = new byte[bmp.Height * bmp.Width * 3];
var rnd = new Random(9001);
var offset = new Point(0, 0);

Console.Clear();

while (true) {
rnd.NextBytes(rndData);

var data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
Marshal.Copy(rndData, 0, data.Scan0, rndData.Length);
bmp.UnlockBits(data);

g.DrawImage(bmp, offset);
}
}
}

Attached: 56wPosfEt.jpg (879x512, 827K)

They're not too stupid. C++ compilers do it all the time with class methods.
The problem is that it's illegal in C.

>Windows
>C#
Must suck having a fetish for slow code.

How to clear screen using termios? And it seems (but I want to check) that there is no termios for C++, so does that mean that I should do
extern "C" { #include }

That's fine, I've had to do that with ffmpeg libraries before.

Tbh, but it kinda sucks there is no ctermios nyeh.

termios is not a standard header.
It looks like a linux header, and those should all have extern "C" already in their headers. You shouldn't need to add it yourself.

>and those should all have extern "C" already in their headers

Attached: 2019-08-18-111258_634x379_scrot.png (634x379, 8K)

>udemy
>discount
[spoiler]Hahahahahahahahahahahahaahahaha ajajajajajaajajajaaja huehuehuehuehuehuehue xDxDxDxDxDxDxDxDxDxDxDxD[/spoiler]
They're always on discount, you gullible moron. The real prices are fake.
And, no, not worth it even for free. It's like buying a youtube video for $10.

Imagine paying for some pajeet-grade videos. Because they're on discount.

Who are you quoting?

My thoughts

this is a very good thread!
even though OPfucked up, based konata is enough to make up for it

> en.wikipedia.org/wiki/John_Smith
DOXXED

>C++ bad!
>why?
>because me say so!

Attached: 1448048148847.png (304x366, 231K)

kys

Attached: 1557062867027.png (425x500, 306K)

Trying to understand how pthread_cancel would work with this code (nevermind its purpose or how poorly written it is, I just want to understand what's happening):

void *f(void *arg) {
while (true) {
pthread_mutex_lock(&mut);
while (cond) {
pthread_cond_wait(&cond, &mut);
}

sleep(s);
pthread_cond_broadcast(&cond);
pthread_mutex_unlock(&mut);
}
}


Say I called pthread_cancel from the main thread to cancel all the threads running this function. Since sleep() is a cancellation point does this mean if a thread is cancelled while sleeping, all other threads can never cancel because 'mut' isn't unlocked after the sleep? Even though 'cond_wait' is also a cancellation point its man page says it first needs to reacquire the lock.

If yes, do I fix it by unlocking before sleep and re-locking before broadcast?

cancelling threads is considered harmful

>C++ bad!
>why?
>k-kys!

Attached: 1462668215806.jpg (1280x720, 102K)

>nevermind its purpose or how poorly written it is, I just want to understand what's happening

I am trying to make a program that takes input from an inputfield, turns it into an array of characters then displays the characters one by one in sequence in a textbox, aka scrolling text in an RPG (I need the characters to be added one by one because I will add mouth animations and sounds based on vowels in the text).
However, in the middle of it, I get this strange error. 0 is less than 3, so the index should be less than the size of the array?
Also sorry for the spaghetti code its been a while since I've written computer programs i'm just trying to get this thing to work at all.

Attached: Help_me_please.png (1456x576, 52K)

man7.org/linux/man-pages/man3/pthread_cancel.3.html
You have to enable cancellation for the thread.
You can cleanup with pthread_cleanup_push I think.

ur cute user

Attached: 1546658963984.png (516x565, 293K)

y-you too

Attached: 1469282654573.png (681x576, 290K)

Can someone post the newest /g programing challenges?

>Forth is useless
>have you actually programmed for resource-limited systems in it? It's quite nice and allows for tremendous levels of abstraction without sacrificing performance nor readability, read "Thinking Forth".
>k-kys

Attached: 1538719485585.png (352x279, 9K)

warosu.org/g/

Anone! It's so interesting watching you practice JavaScript!

Attached: d82b936b5c854be5e863d246380a0c42.jpg (918x1200, 134K)

What's the point of C++ if only a select few projects using it write optimized code?
What's the point of Rust if it's merely a non-sequitur to every problem a large C project faces?
Both are as disgusting as Java, perhaps even moreso. They don't have a convention (or a decent standard library and tools for that matter) that makes them suitable for rapid development nor are they fit for hardware interaction and kernels where executable size and predictable code is desired.

Cant you just display your inputted text in a for loop without all the other stuff?
On mobile so near with me
for(int i = 0; i < lengthOfText; i++)
print(text[i]);
wait(1);

pseudo code but you have like five string variables for one string.

I'd prefer to watch you though because you're so cute!

>textProgress

>What's the point of C++ if only a select few projects using it write optimized code?
the point of it is C with classes and templates, I don't see what's not to get.
>What's the point of Rust if it's merely a non-sequitur to every problem a large C project faces?
forgetting to free memory, use-after free, and race conditions are really really common bugs in C/C++ projects.
>Both are as disgusting as Java, perhaps even moreso. They don't have a convention (or a decent standard library and tools for that matter) that makes them suitable for rapid development nor are they fit for hardware interaction and kernels where executable size and predictable code is desired.
I can't even tell if this is bait or not

>What's the point of C++ if only a select few projects using it write optimized code?
What's stopping you from writing optimized code?

>forgetting to free memory, use-after free, and race conditions are really really common bugs in C/C++ projects.
Rust also leaks memory but I guess it's different because it ``Safely`` does so.
>What's stopping you from writing optimized code?
Why would you do that in C++? the result is C-- with the C stdlib plus thousands of const related keywords and little to no templates use.

must suck not having a job. save the larp in your reply.

>Why would you do that in C++? the result is C-- with the C stdlib plus thousands of const related keywords and little to no templates use.
No that's C style code, not optimized C++ code. They're not the same thing.

>language wars
just use java.

Attached: images.jpg (300x168, 25K)

>Today the greatest expense in programming is the cost of a programmer's time.
>Modern languages such as C++ make it faster to produce well-written, easy-to-mantain programs that can be extended and enhanced.

Attached: gabriela_lotarynska_cpp.jpg (806x720, 80K)

>They're not the same thing.
They are if you care about cache-friendliness else you are not writing optimized code at all.

I'm so tired of all those damn 47 yo legacy languages coming in, stealing our jobs, and impregnating our wimmin!!!!!

>cache-friendliness = C code
LOL
youtube.com/watch?v=j9tlJAqMV7U
Where is the C code again?

>Modern languages such as C++ make it faster to produce well-written, easy-to-mantain programs that can be extended and enhanced.
HAHAHAHHAHAHAHAHAHA

Attached: 14456756344235.jpg (317x267, 12K)

Good thing being cache friendly has nothing to do with writing C style code.
You really have no idea what you're talking about. Please learn a bit about programming languages.

>Rust also leaks memory but I guess it's different because it ``Safely`` does so.
Rust can leak memory if you create Rc cycles. In my experience it's not really a common issue. Still, if you're writing super complex inter-referencing code then I believe there are crates tailored for avoiding reference cycles.

>cppcon
>not spreading fud about other languages other than sepples

cppcon rarely ever talks about any language other than C++

Python is a joke because half the libraries are actually written in C for performance reasons

I think the best part about Rust and the whole "memory safety" bullshit is that it's not even possible to implement a GC language in rust without giving up the memory safety stance.

Just think about that a language made originally for Firefox wouldn't even implement the Javascript interpreter without being unsafe despite all the safety hype.

The only time they talk about other languages other than C is when they present an idea or feature and they implement the same thing but improved in C++

>C
>performance
ナイスジョーク

>they implement the same thing but improved in C++
Now that's funny. Can't wait to see how they improved contracts from Eiffels when they eventually add it in C++36

I think you're missing the point of Rust.
The point isn't to eliminate all unsafe code what-so-ever because that's impossible. There are just some things that are inherently unsafe.
The point is to allow for unsafe code to be explicitly marked and then to build safe abstractions around it. That way you only have to verify your unsafe blocks where as in say C you would have to verify the entire code base because everything is unsafe by default. You aren't guided to where the bug might be.

the practical result is that doing anything useful is considered unsafe unless you overengineer the fuck out of it

I'm not really sure what you mean. Do you have any examples of useful but unsafe things unless you overengineer?

Firefox
Rust OS w/e that was called
remacs
...

Global variables with heap allocations.

you completely miss the point of "safety".
if that was the desired goal, rust would be more akin to a proof assistant or support dependent types, even then you would continue to argue about muh unsafety because of postulates and other shit to circumvent the termination checker...

I was more asking for specific examples inside the codebase. Yes all those examples use unsafe but the percentage of unsafe block is small compared to the total code base.

The lazy_static crate? Again, my point isn't that Rust eliminates all unsafety, it's that unsafe things only have to be done once and then everyone else can use those unsafe things as if they were safe.

I think we're talking about different degrees of safety. Rust's goal was always to wipe out the vast majority of memory safety bugs that plagued other systems programming languages. It was built like this because that's what they needed for Firefox. A language that can build a performant web browser that will also have significantly less vulnerabilities than a C code base would.

while eliminating vulnerabilities and bugs is the desired goal, that is not what memory safety or type safety means.

fug, I just realised I completely misread what you wrote and who you were responding to.

>hire three pajeet programmers for the price of one C programmer
>have to design and maintain an entire language to keep your pajeets employed
It's not a surprise Firefox has become worse and worse over the years. They should just switch to chromium and get the trip to hell over with as fast as possible.

Data Scientist (TM) (R) (C) here. Been using R for +5 years due to my scientific background (Statistics and applied math). Now I am on the lookout for a new job and it seems no one gives half shit about my knowledge in statistics and they want me to be an """"expert""" in Python. Since i am still a wagie, I have no choice but to learn it. How long would it take for me to learn Python? What are the essential libraries other than Pandas, Numpy, and SciKit learn?
In R I worked extensively with libraries like mlr, h2o, tidyverse, ggplot2, DBI, RODBC, reshape2, HydroGOF, rcolorbrewer, and many more. I want the transition to be as painless as possible as it is difficult to teach an old dog, new tricks.
Any advice will be greatly appreciated.

Attached: bork.png (596x379, 71K)

Just use Julia, it's perfect for the matlab and R people and also has perfect python interop

python is brainlet friendly don't worry

not for any inherent reason though. It's just had the meme of "python is easy" for so long that the requisite documentation has been constructed around it, like an Iron Man suit for a pig.

For some reason I spent all of Friday night fucking around with regex trying to parse out some shit document. Didn't know it that well before, but now I do.

I just started looking into sed.. It's a big confusing mess, but I feel so powerful! I can't wait to manipulate my company's java code with this.

You probably need to find more jobs related to your field. Universities might have jobs like that, or maybe certain businesses (I hope you have business related experience). If not, you're in a rather niche field, which is why companies can be total cunts about who they're hiring.

Obviously I need to learn awk now, but where do I go from there? Bash scripting? Forth? ... Idris???

I definitely prefer using Perl, over bash/sh and other built-ins for a bunch of things. Perl can run on Windows, too (Strawberry Perl), and it's syntax is far saner and less aggravating than bash/sh/cmd.

If you have any regex questions or examples, share. I like regex.
$val =~ m/
([\$%@]) # sigil
\{ # mandatory open curly
[\w]+? # variable
}# mandatory close curly
[\{[]? #optional open thing
[\w\ ]* #optional index
[}\]]? #optional closing
/gx

>It's not a surprise Firefox has become worse and worse over the years.
>implying chromium isn't becoming worse and worse too
I hope you get paid for this shilling

after that, you can learn a real programming language and forget all of your sed and awk knowledge.
Historically the most sed/awk-defeating language was Perl. Ruby is nearly as good but you'll have to read 'man ruby' yourself and practically only Perl knowledge will help you use the features there, since Ruby people don't know about them.
If you're comfortable continuing to use sed/awk for oneliners, but doing anything even slightly more involved in a real script, then more languages open up to you, including non-shit ones like D (with rdmd), OCaml (with ocamlscript), ...

I hate chromium ever so much more than Firefox's things. I'm just wishing we can go from trash to trasher as quickly as possible, instead of this long drag-behind-the-motorcycle-of-death we call Rust/Firefox

Julia might be the next great thing but now no one is demanding it and pipelines are in mostly in Python/sometimes in R.

I have been in business for almost a 1.5 years, marketing and sales analytics to be exact. I gained great amount of knowledge and how slimy the business world is. Thing is that most of my work was solo, so I had the freedom to work with any tool I like as long as I provided a proper solution to whatever problem our client had. Now that I am applying for new jobs, many of them work in automated pipelines, I have no issues learning stuff like Docker or dealing with Data Bricks from Azure or working with SQL which I am also experience with. The issue is that I will need to read the Python scripts inside these pipelines and maintain the mathematical models accordingly. I am not looking to do any sort of webdev or programming in Python. I just want to use it as a data analysis tool. I also noticed that during my last few interviews in the previous weeks, I handle myself perfectly and they like everything about my experience except for Python. Since we are dealing with HR brainlets I have to also tell them that I am good with Python but I can't lie about it either when the test phase comes.
sorry for the blog post.

Nah I'm in the same boat. I applied to over 200 jobs as a C/Perl debugger, and every single time if you aren't immediately an expert at C++, anything, they'll show you the door. Companies don't want to spend a dime on training, and then every company is going in the shitter because of it.

Attached: fuck everybody.png (1370x994, 83K)

which website is better to use between hackerrank and leetcode? What does one offer that the other one doesn't?

>Companies don't want to spend a dime on training
i am not even expecting to be trained, just to be given a chance. I had no knowledge of SQL before my current job. Had to teach myself everything until I became better than the people there themselves.
Anyway back on topic, what are the essential packages in Python if I am moving from R? The first I am gonna do is port all of my R code to Python, I think that will be very good training for me.

reeeegeeeex

Attached: headerscanner.png (2555x1402, 367K)

just get a python book, or start at python.org/doc/ , and start learning.
if you spend a day on it you'll have a much better idea about how hard you're finding it and what you'll need.

none have anime girls to congratulate you when you finish a problem, or to tell you ganbatte when you're getting tired of grinding. So they're both trash

I know chrome isn't chromium but I'm still a little surprised you bring it up in the context of a pajeet straitjacket language.
Go is unarguably the pajeet straitjacket language. The capable google engineers who made the language liberally used generics (templates) in their C++ compiler for the language but didn't expose them for to the Go programmer. Presumably because they thought users of their language were too stupid to either understand them or use them correctly.

ATTENTION ALL /vg/ GAMERS:

vgstats,xyz

Attached: 1564131872202.png (330x470, 130K)

>used generics (templates) in their C++ compiler for the language but didn't expose them for to the Go programmer.
that's not how it works, but whatever