/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Previous thread:

Attached: dpt.png (1023x858, 535K)

Other urls found in this thread:

visualstudio.microsoft.com/vs2019-launch/
kernel.org/doc/html/v4.10/process/coding-style.html
suckless.org/coding_style/
doc.cat-v.org/bell_labs/pikestyle
github.com/awesomekling/serenity
youtube.com/watch?v=t-QSmNReDyI
publications.gbdirect.co.uk/c_book/
cs.rit.edu/~ats/books/ooc.pdf
twitter.com/NSFWRedditGif

First for great C

kotlin is ugly

NOOOO
YOURE WRONG
SHUT UP

This is your reminder that silverlight is a dead piece of shit and you need to stop using it

just finished reading through the whole metaclass proposal
and holy fuck
i want it
i need it
i must have it

I don't think any Netflix employees browse Jow Forums.

mein negger

it's taken me a long time to realise that C++ programmers really deserve C++
as soon as they understand how bad on every level the language is, they're baited with some new feature and instantly forget

How can someone praise Python and hate on JavaScript in the same conversation? Either opinion is fine on its own but together, it breaks down. Are they high or what?

The more I learn about C++ the less I want to use it. Is this normal?

Yes

it's not like you're not wrong
but why did it take you so long to realize it

you have to be a certain kind of person to enjoy c++
so yes

Happened to me

The language is ridiculously complicated and even the "new, memory safe" C++ is memory unsafe if you use it wrong

Can you explain what is bad about C++? Do you think C is bad too? Do you just mean it is bad for your Dating App side project?

I basically only know Python well, and I know some C. I want to get better at C, but I don't really know of any fun C projects. With Python I can relatively quickly bash out an idea, and I have no real shortage of fun projects, but with C I don't really know what I want to make. Give me some ideas, preferably something not too complex, but that is easier to do with C than with Python.

Also recommend me some style guidelines, along PEP8, but for C. Thanks amigos.

Attached: 1526921057960.jpg (350x428, 77K)

>The standard libraries offer very poor functionalities compared to other languages' runtimes and frameworks.
>C++ doesn't enforce a single paradigm. Neither procedural nor object-oriented paradigms are enforced, resulting in unnecessary complication. [Some people consider this as an advantage.]
>Too hard to implement and to learn: the specification has grown to over 1000 pages.
>Everybody thus uses a different subset of the language, making it harder to understand others' code.
>Not suitable for low level system development and quickly becomes a mess for user level applications.
>The standard does not define exception handling and name mangling. This makes cross-compiler object code incompatible.
>No widely used OS supports the C++ ABI for syscalls.
>There is try but no finally.
>The exception system is not integrated with the platform: dereferencing a NULL pointer will not throw a C++ exception

Do I install visual studio community 2017 or wait 1 week for the 2019 lauch (or would that be buggy)

poorly designed, features do not integrate well with one another, filled with bizarre pitfalls

it's an autistically worded bloated junkheap held back by an obsession with backwards compatibility that somehow has obtained a great dearth of useless features while actually useful ones have been sidelined, which means that developers tend to have to resort to extremely esoteric workarounds or (source) code generation tools for basic productivity

it's a comfy junkheap though, wouldn't trade it for anything

>poorly designed

What new features does 19 have? I wonder if I should upgrade.

I'm adding support for threads to my operating system.
It was unpleasant that the file manager would freeze for 5-6 seconds when entering a directory with lots of images, in order to generate the thumbnails.
After a day of hacking, I now have basic multi-threading, and I can do the thumbnail generation on a secondary thread :)

Attached: threaded_thumbnails.webm (1024x768, 1.17M)

no idea I just went to the website and saw this
visualstudio.microsoft.com/vs2019-launch/

C is simple and doesn't try to do all the things for all the purposes C++ does. C's new revisions of it standards barely make any changes. C++ keeps adding more and more wacky features every decade and the old features continue to exist.

C++ will be relevant for a long time to come, but increasingly for new projects people are choosing languages that were designed to be memory-safe from the ground up and don't have an endless labyrinth of dark corners of the language standard for developers to hide their code in. As time goes on I think it will be considered a legacy language for userspace projects the same way C is.

Its compilers are state of the art, which gave it an edge for a long time, but LLVM's ubiquity and ease of use for language developers has put really powerful optimizations into the hands of many other languages. So honestly I see C++ sticking around for legacy reasons.

>metaclass
you guys are a bit late

>Not suitable for low level system development
What constitutes as low level system development? I thought people used C++ for things like video game engines and operating systems.

both those things are "low level system development"

local html static site generator for remote deployment on cheap hosts to take advantage of real time seo terms within minutes of current events for ad purposes if course... LAMP for life

the big feature they're shilling is that in return for all the personal information you gave it the botnet will program for you or at least make things easier

C is unironically garbage

C++ is so ridiculously overengineered that very few people on the planet fully understand the language, and most of the people that do are on the actual committee for designing it. It's a huge incoherent blob of poorly implemented features and ugly syntax.
Unfortunately, for the few things it is still the best choice for (i.e. vidya games), it will not be replaced in the near future because the alternatives tend to repeat the same mistakes.

>Also recommend me some style guidelines, along PEP8, but for C.

kernel.org/doc/html/v4.10/process/coding-style.html
The only somehow popular alternative is the gnu style (it's shit).

all im reading is "c++ is too difficult for my curry filled brain"

cope

Haven't been to /dpt/ in a while, this project is new to me. Is this actually a real OS running in QEMU? How much of it did you write yourself? (e.g. is the kernel an existing kernel project?)

Go write your code in malbolge then

Sudoku solver is nice and short.
>style guidelines
Common sense is enough. Suckless is bretty gud but they go overboard sometimes.
suckless.org/coding_style/
If you want advice on programming, check out Rob Pike's style guidelines:
doc.cat-v.org/bell_labs/pikestyle
Why threads and not something like async/event loop?
Absolutely nobody writes likes that. Who the fuck uses eight spaces?

>Who the fuck uses eight spaces?
C grognards

>8 character indentation

Attached: 1550713362781.jpg (1024x576, 76K)

games have largely been taken over by C# and scripting languages (Lua, Python, JS). The days of writing engines are over. Things are just too complex to get into now. OpenGL is so irreparably splintered, there's multiple graphics APIs for every platform and none of them are cross platform... Let alone sound, windowing, input, etc.
No wonder everyone just uses SDL or MonoGame and sticks to pixely 2D games.
Same with C++. It's just too much. Beginners used to be able to pick up C++ with just the hurdles of learning about classes and pointers and that was it. Now there's STL this, 'rvalue references' that, so much esoteric C++-specific jargon all over the place.

Hi user, and welcome back. This is my Serenity OS running in QEMU. Sources here: github.com/awesomekling/serenity

I've written about 99.8% of it myself. 5 or so libc functions are copied from BSD licensed projects because I didn't want to implement them at the time, and then I just never get around to replacing them with a home-grown version.

>First off, I’d suggest printing out a copy of the GNU coding standards, and NOT read it. Burn them, it’s a great symbolic gesture.
>Tabs are 8 characters, and thus indentations are also 8 characters. There are heretic movements that try to make indentations 4 (or even 2!) characters deep, and that is akin to trying to define the value of PI to be 3.
He's like every obnoxious programmer stereotype come to life

>games have largely been taken over by C# and scripting languages (Lua, Python, JS). The days of writing engines are over
Don't post bullshit please
All real games still write their own engines in C++
C# with Unity has only become the defacto standard for small developers

baserad

>Why threads and not something like async/event loop?
To maximize responsiveness. I already have an event loop, but if I were to do the image decoding there, the app would stutter if you tried interacting with it while decoding runs.

Besides, I was gonna need threads sooner or later anyway, so it was as good a reason as any to work on it.

>C# with Unity has only become the defacto standard for small developers
small developers are largely what I'm discussing. Average programmers. You and I. I could not care less about what inane shit big companies are doing, with codegen, asset pipelines, writing out every platform configuration themselves and abstracting it away with their own in-house tools, I'm talking about what individual programmers use for their own projects.

JavaScript is markedly worse than Python

Well personally I write my own engines too but there is no 'average programmer' here there's a pretty even split between AAA developers and indie developers
If you are a competent programmer you shouldn't be telling yourself things like "the days of writing engines are over", because they aren't, not even close

So average 60k salary hireling are using scripting languages while the big boys are using C++. Thats what I suspected hehe
I couldnt imagine trying to work with a team using c or c++, it is hard enough in simple languages where you import a framework and call a few functions

Wow that's insane, is this running in x86 real mode, or protected mode? You have a partial implementation of libc to call into your kernel functions? This is literally amazing and I think I've never seen something like this shown in /dpt/. Wow.

Can you explain to me why that is? Like, what's the primary differentiator(s) for you?

The average 60k hireling is using C++. The average artist who dips their toes into programming to make games is using C#

It's running in x86 protected mode with paging. Multi-process and multi-thread (as of today) :)
I've only tested it in emulators though. I'm sure it's gonna be a pain when I eventually try to migrate onto real hardware.

An x86 decompiler that can be recompiled with gcc at any point

Looking at the memory constraints, this has to be in protected mode. Seriously cool. I'm really excited you put the source on github, even if you haven't chosen a license yet

>Absolutely nobody writes likes that. Who the fuck uses eight spaces?
forces you to keep your code readable

I'm almost there.

Attached: dptarchive.png (1898x929, 94K)

>Can you explain to me why that is? Like, what's the primary differentiator(s) for you?
JavaScript encourages functional paradigms, which leads to people writing shitty illegible code.
JavaScript by necessity leans heavily async by default, which caused JS devs to go on a 5 year crusade of callbacks, promises and async/await in order to reason about basic control flow.
Python is still dynamically typed, but its type system is still more strict and more predictable than JavaScript. 1 is not equal to "1", and you don't need to use a separate operator to make sure the language doesn't think it is.
Python treats run time errors as fatal errors and halts execution, JavaScript treats errors as minor inconveniences and tries to power through them. Perhaps a necessary evil to allow new programmers/bad programmers to write code for the web by allowing their shitty broken programs to eek out something that technically works, but an evil nonetheless.
lol whitespace affects JS execution speed

>>whitespace affects JS execution speed

kek

help I am trying to understand objects in a specific case
>Syncfusion.PdfGrid bullshit

>// Make a parent grid and add a column to it
PdfGrid objParentGrid = new PdfGrid();
objParentGrid.Columns.Add(1);

>// Add 2 rows to the parent grid
PdfGridRow objParentFirstRow = objParentGrid.Rows.Add();
PdfGridRow objParentSecondRow = objParentGrid.Rows.Add();

>// Make a child grid and add a column to it
PdfGrid objChildGrid = new PdfGrid();
objChildGrid.Columns.Add(1);

>// Add a row to the child grid and set the value of the first column (Cells[0])
PdfGridRow objHelloRow = objChildGrid.Rows.Add();
objHelloRow.Cells[0].Value = "Hello";

>// Assign the child grid to the value of the PARENT grid's first row's first column
>// Nested Grids are legal
objParentFirstRow.Cells[0].Value = objChildGrid;

>// Here's the start of the part I'm confused with
>// new child grid, with 1 column
objChildGrid = new PdfGrid();
objChildGrid.Columns.Add(1);

>// Add a row to the new child grid and set the value of the first column (Cells[0])
PdfGridRow objWorldRow = objChildGrid.Rows.Add();
objHelloRow.Cells[0].Value = "World";

>// Assign the new child grid to the value of the PARENT grid's second row's first column
objParentSecondRow.Cells[0].Value = objChildGrid;

>//Here's where PARENT actually gets drawn on the page
objParentGrid.Draw(PAGEOBJECT, XYLOCATION, XYBOUNDS);

The question is do I see
>Hello
>World
or
>World
>World
because I made the child grid a new object after I did "Hello", does "Hello" still exist and get drawn? Or is it a null value? Or is it overwritten with "World"?

I am trying to avoid pagination by using this Parent Grid rather than drawing the Child Grids one by one and calculating where on the page the XY bounds and location should be.

Where can I see examples of the State monad used effectively in Haskell?

I've just read the wikibook chapter about it and I don't know, everything about Haskell seems intriguing and exhilarating to me but at the same time I can't help but think it really isn't practical lol
I should read some actual project written in Haskell but haven't had the time yet

>If you are a competent programmer you shouldn't be telling yourself things like "the days of writing engines are over", because they aren't, not even close
I suppose I was being dramatic in saying that, however, writing a cross-platform engine used to be a lot easier than it is today. I could spin up C++/SDL/OpenGL 2 and have a 3d engine with shaders and everything in an afternoon. Now, opengl2 doesn't work on opengl 3+ platforms, opengl 3+ doesn't work on opengl 2 platforms, apple abandoned opengl entirely in favor of metal, and opengl sucks on windows (though I suppose that's never been any different). So now I have to maintain 3+ pipelines of OpenGL (of different versions), DirectX, and Metal, in which case I might as well just use the OS's native windowing system since I already have those pipelines anyway. Except, wait, windows has like, what, 5 UI toolkits now? And Linux has 2 (which both suck)? Guess I'll use native X11. Or Wayland. Who knows. And I don't even know about OS X because I don't use it, and previously I didn't have to. Oh well to that too.
There's just a lot going on now that didn't have to happen before.
None of this is about competency it's about things being arbitrarily difficult because each platform wants things to be 'their way' and fuck everyone else.

Not even mentioning mobile or console.

the big thing that opened up haskell to me is to stop writing imperatively altogether. It's really easier to write things declaratively instead, starting at the solution you expect and working backwards. State is preserved through function calls, not through variables.
I don't have an example of the State monad, sorry.

Wow, I'm still just so shocked at seeing this. I saw lost+found on the drive you had, does that mean you can compile fsck for serenity using your libc implementation, or was this disk fixed in the past while you were working on your own ext2 implementation or something?

>JavaScript by necessity leans heavily async by default, which caused JS devs to go on a 5 year crusade of callbacks, promises and async/await in order to reason about basic control flow.
Yeah admittedly callback hell was/is a real problem, but async await was the solution. Using it properly I think modern JS doesn't suffer from major deficits in that field.
>Python is still dynamically typed, but its type system is still more strict and more predictable than JavaScript. 1 is not equal to "1", and you don't need to use a separate operator to make sure the language doesn't think it is.
JS today doesn't use the == operator. I think it's annoying to have old unused features but no one seems to mind ignoring C pointers in C++ or using Python 2.7 because of a Python 2 dependency despite it being almost 10 years old.
>Python treats run time errors as fatal errors and halts execution, JavaScript treats errors as minor inconveniences and tries to power through them.
This isn't true, an error in JS walks up the callstack until it hits a try-catch or if not, logs to the console. Failures completely kill a JS execution, but it's not like it's going to crash your tab or take down your browser or something. The sandbox doesn't have the authority to do that.
>lol whitespace affects JS execution speed
...no?

The only platform people play games on that isn't mobile or console is Windows, in which OpenGL 2 and 3 work absolutely fine

I just realised now I could have shortned this whole post and just asked:

List ourList = new List();

object HW= new object();
HW.Value = "Hello";
ourList.Add(HW);

HW = new object();
HW.Value = "World";
ourList.Add(HW);

foreach (object WORD in ourList)
{
WriteLine(WORD.Value);
}

am I going to see:
>Hello
>World
or
>World
>World

Thinking about ideas for a very simple low level language for a fantasy retro console. Basically you can store and read 8bit words, and do unsigned integer arithmetic and logical operations on them. You can goto whatever line and resume execution from there, and you can label these lines, and check the results of operations to branch. So basically assembly. But im trying to figure out how i would make it more high level without actually making it high level.

SDL + Vulkan, handles mobile, too.

mandatory:
youtube.com/watch?v=t-QSmNReDyI

C is the comfiest language i've written in a while.

Jow Forums has code tags, read the sticky

All languages are unsafe if you use them wrong. Even JS can crash a plane.

>// Add a row to the new child grid and set the value of the first column (Cells[0])
>PdfGridRow objWorldRow = objChildGrid.Rows.Add();
>objHelloRow.Cells[0].Value = "World";

should be objWorldRow.Cells[0].Value = "World"; instead?

You'll see hello world. the objects you are making still exist in memory, you the programmer are just losing access to them ie. a memory leak. In this case the list object will contain both of the text object.

When you create a new Ext2 file system with mke2fs, it automatically adds a "lost+found" to the root directory by default.
I've never actually tried building e2fsprogs (which is where e2fsck comes from) for Serenity. I tried it now and it fails to build due to missing support for flock() and ftruncate() in LibC.
That said, on my host machine I regularly run e2fsck on the disk images I use for testing, to verify that my file system implementation is mutating the file system correctly.

I see. That's a really cool project user, looking forward to future updates.

So apparently decltype((var)) means decltype(var) &

Thanks user! Happy to talk about it

Attached: catcafe.jpg (736x736, 67K)

A while back I started using Selenium to fill in the contact pages of psychics and send them lots of emails of movie scripts like Free Willy and Passion of the Christ. Any way to make this funnier/ faster? I already started automating copy/ paste key commands and multithreading in browser tabs

hot tip: open the style inspector on both and compare them
looks like you're missing font, border, and margin/padding

>should be objWorldRow.Cells[0].Value = "World"; instead?
yes good catch, I was copy pasting and not really proofing the post

thank you again user now I can go to bed and sleep easily

eva best anime all time

how do terminals and shells parse commands? I'm making a CLI program and I'm using regex, but it doesn't feel right

...

Tokenization, read about it. Or read about yacc.

I wanna learn C in depth, is this THE book to start with?

Attached: 51TGEPRTDNL._SX377_BO1,204,203,200_.jpg (379x499, 27K)

Is it normal for C code to look this ugly, or it this just my inexperience? I had a bit of an issue with a function that was supposed to return both the number to fill in, as well as the position of that number, since I don't know the proper way of returning multiple values from a function, and it feels wrong to pass around pointers to arrays.

Attached: code.png (707x921, 38K)

as far as C code goes, that's not very ugly at all

is there any language that excels at compiling programs for multi core processors? no need for garbage collection, i just don't want to deal with concurrency bullshit in C
yes, if you are beginner though, have this to help you on parts you get stuck: publications.gbdirect.co.uk/c_book/

Nothing ugly with that code, and passing pointers of arrays to functions is standard in pretty much every language, only in c it's explicit and not implicit

use 'while' instead of 'for' and see if you like it.

>K&R - The C programming language
basic stuff
>Stephen Prata - C Primer Plus
basic stuff + some advanced C98/C99/C11 stuff with exercises and other shit
>cs.rit.edu/~ats/books/ooc.pdf
OOP in C
>Peter Van Der Linden - Expert C Programming. Deep C Secrets
Some stories about C language with some C tricks and pitfalls
>Richard M. Reese - Understanding and Using C Pointers. Core Techniques for Memory Management
The name speaks for itself
>Ben Klemens - 21st Century C: C Tips from the New School
Same as above
>P. J. Plauger - The standard C library
Just

>Use /* */ for comments, not //
Fuckless should be gassed.

Use spacing.
for (int i = 0; i < 9; i++) {

Preferably, use clearer variable names, such as y and x instead of i and j - there's nothing that really says that x is "inner".
Don't use magic numbers.
puzzle[i][j] = getc(fp) - '0';

Don't explicitly check zero, and don't use imperative form for pure functions:
while (!solved(puzzle)) {

What does the magic "simple_solve" do? Go through the array and count how many zeroes? It'd be clearer to refactor this out.

Make the code for row and column common. As it is now, it can't handle boxes, nor stuff like this:
... .1. ...
... ... ...
... .3. ...

... .9. ...
2.7 5.. 8.4
... .6. ...

... ... ...
... ... ...
... ... ...


There's a website that I don't remember the name of that shows progressively more and more advanced (desperate) sudoku solving algorithms.

Can anyone point me in the direction of a good resource to learn OpenCL? Examples of programs that do simple stuff are very welcome too.

Yeah, I feel that the way I'm handling the structure right now isn't the best. I've got nested for loops to go through my 2D array representing my puzzle, but if I want to say, go through each element in each box that would be essentially 4 loops, two for the x and y for the box, and 2 for the x and y of the element inside the box.

I should do as you say and just write three functions, one to extract a column, one to extract a row, and one to extract a box. I've got some box logic implemented now, but it's what's currently giving me the worst code.

simple_solve simply checks if a row has only one unknown, and if so, returns what number should be there. This is awkward, and I should instead have each function "act" on each number. So each number gets performed on, rather than rows or columns.

Attached: code.png (681x886, 25K)

it took me a year and a half of coding to use of a stack implementation, and I still havent made use of a queue

Attached: 1500400813745.png (601x508, 127K)

Refactor more. The puzzle[x][y] nonsense isn't very needed, generally in C we just use straight arrays and a macro for indexing.
So something like
#define SMALL 3
#define LINE 9
#define BOX(n, i) (SIDE*(n%SIDE) + i%SIDE) + BIG*(SIDE*(n/SIDE)+(i/SIDE)))
#define ROW(n, i) (n*LINE + i)
#define COL(n, i) (n + i*LINE)

Then you've abstracted away all of the row, column, and box peculiarities.
>int possible_numbers[9] = {1,2,3,4,5,6,7,8,9};
Another pythonism. No need to store data in more than one place, just use the loop index. So do
int filled[9] = {0}; //set to 1 if found, then use the index instead

r8
#include

char look(char arr[3][3], int row, int col) {
printf("(%i, %i): %c\n", row, col, arr[row][col]);
}

void scan(char arr[3][3]) {
int LenOfSide = sizeof(arr[0]);
int i, j;
for (i = 0; i < LenOfSide; i++) {
for (j = 0; j < LenOfSide;j++) {
look(arr, i, j);
}
}
}

void printGrid(char arr[3][3]) {
printf("%.*s\n", 3, arr[0]);
printf("%.*s\n", 3, arr[1]);
printf("%.*s\n", 3, arr[2]);
}

//a bunch of pseudo-code comments that elaborate on functions to-be-added

int main() {

char grid[3][3] = {
{'X','O','_'},
{'O','_','X'},
{'X','_','X'},
};

printGrid(grid);
return 0;
}

what part are you struggling to understand user?
Generally when a problem becomes hard to solve, its good to get a fresh perspective on it.

Looks like stereotypical boomercode, just needs some typedef'd structs and BSD-style function declarations. Not that there's anything wrong with that.

Too much hardcoding/magic numbers, use a define and loop.

X can never reach that position, O would have to have at least one more.