/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Previous thread:

Attached: tech_is_power.jpg (1200x900, 211K)

Other urls found in this thread:

maritain.nd.edu/jmc/etext/catsum01.htm
en.wikipedia.org/wiki/VHDL
ada2012.org/
spark-2014.org/
newadvent.org/summa/1002.htm
youtube.com/watch?v=bFtcLJVN8yg
youtube.com/watch?v=0yXwnk8Cr0c
dailyprog.org/♯∕g∕dpt/
benryves.com/tutorials/winconsole/
twitter.com/SFWRedditVideos

Anyone do pic related?

Attached: 1528280743417.jpg (750x750, 102K)

>Who are you empowering?
>Chrome

Never. Not unless it actually, legitimately, has a proper use. For example I've turned compiler bugs into implemented features because they actually did do something useful. The compiler bug is eventually fixed and the feature remains in a properly implemented form.

Why do *I* have to empower somebody? Why can't you do it, if you're complaining about it?

if a function returns multiple values in rust how do I assign those to already declared mutable variables?

Your actions are empowering someone whether you intend to or not.

Friendly reminder programming isn't a subset of anime. As there are no proofs which validate the claim

You can't, not directly. You have to do:
let (x, y) = foo();
u = x;
v = y;

AFAIK there's an RFC for what you want, since I believe Rust doesn't assume a specific memory layout for a tuple (which would be a barrier to this working, at least with RVO).

ok thanks

God is real since you cannot prove he isn't.
God is also not real since you cannot prove he is.

C++ doesn't have this problem.

God is ill defined.

Attached: C++ programmers.jpg (1200x1574, 231K)

Actually, proving God's existence is quite simple. See: maritain.nd.edu/jmc/etext/catsum01.htm

Boost in a nutshell

There's a balance of self documentation and feasibility in building easily maintained and large scale systems. C++ has user defined structuring of regions of memory, and interfaces for changing the state thereof. Yes, you're going to have to dig in and figure out how that system works.

That's not saying some programming styles and intentional approaches aren't sloppy, obnoxious and difficult to parse, but nonetheless. Targetting C++ is foolish, tribal memery.

They did a good job of hiding the assumptions and definitions but it falls apart with a stern glance.

>prof: "hurr durr u must write thats easy to read for humans"
>real life comes
>literally every successful library is an unreadable mess

I'm a VHDL guy looking into real-time Ada/SPARK embedded systems programming.

en.wikipedia.org/wiki/VHDL
ada2012.org/
spark-2014.org/

If you want more than just the "executive summary", then here you go: newadvent.org/summa/1002.htm

DOCUMENTATION, NIGGA
youtube.com/watch?v=bFtcLJVN8yg

How do I stop being a shitty programmer

Learn C, then use C.

How am I supposed to impress modern cs qts with C though? :thinking:

An hero on discord live stream

Learn modern C++. Then learn C.

Learn C then modern C++.

learn Haskell

Nobody should use C++ for any purpose.
Every minute you spend writing C++ objectively makes you a worse programmer.

lel kys

Explain.

literally no choice tho

youtube.com/watch?v=0yXwnk8Cr0c

Searching through python code from years ago to find sql queries that are hardcoded and assume not only the database name, table names, and column names, but also in some places assumes that certain values were filled in, so that I can reverse engineer in the missing tables/columns I need to test shit.

On a side note, what's the oracle equivalent of Microsoft's SQL Server Management Studio? (I don't know shit about databases if you can't already tell.)

Are private fields a meme?

why does java continue to send tcp retransmissions past the timeout paramater in milliseconds? I want it to close the socket once the timeout has been reached
Socket a = new Socket();
a.setSoTimeout(4000); //keeps retransmiting tcp SYN even if no response after 4 seconds

define private

As in C++
class ... {
public:
int foo;
private:
int bar;
};

>work as a C++ dev, 14/17
>suddenly a wild C project appears
>spend a week tinkering with C
>feels like a breath of fresh air
>literally crying
>"I'm home"

why teach students coding practices and conventions if no one on shithub fucking uses them

It was all a scam. Its all about lazy teachers wanting students to make code that can easily be evaluated.

>imblying shithub == whole world
user

They're compile-time features. It's just like assert(), if something is marked private, and something is trying to access it directly, it is caught at compile time.

That's it.

it all makes sense now

Attached: 1500191644188.jpg (478x750, 84K)

If you don't wanna anyone else messing with bar, making it private is a way of saying "you dumb faggot better not change this variable outside of its class or you will fuck the whole program up"

why is java being so retarded?
it is keeping sockets open past 4 second timeout

Attached: hot anime girls.jpg (1500x872, 340K)

strings

true, though (for clarity) in this case you'd have to use std::tie() rather than a structured binding

as a side note, C#'s tuple literal / deconstruction syntax allows binding to existing variables. it also allows tuple elements to be named, and the compiler can pull the names into calling scope when a tuple is returned from a method, which is pretty cool

Cringe

Attached: 2413167565267036.gif (400x400, 7K)

The ability to have variables and functions be private is very useful. Fields are just a method to allow you to not have to rewrite public/private/protected/etc over and over and over again for every variable or function.
Makes me wonder if the following works: unsigned:
int i;
char c;

yeah literally just return a closure

holy shit i fixed it by doing the following (what the fuck is the use of the setSoTimeout() method if it doesnt do what is intended?
Socket a = new Socket();
a.connect(new InetSocketAddress(mRemoteAddr, mRemotePort), 4000);

You can also discard or treat the return as a one valuetuple entity/struct

I finally understood pointers

Attached: 49835.gif (280x438, 52K)

I guess you got the point

unsigned i;
for (i=0; i

Indeed

Attached: 1521510254141.png (810x793, 576K)

I am guessing setSoTimeout must be called after connect?

c++17 has structured bindings
you can do
auto [x, y] = foo();

however you have to provide variables for all the values even if you don't want them

fn main()
{
let (mut thing,mut thing2) = return_tuple();
println!("{} and string is {}",thing,thing2);
}

fn return_tuple()->(u32,String)
{
(1324,String::from("Rust does not have this problem either"))
}

>modern cs qts

Attached: 1502765290505.jpg (803x688, 141K)

ignore me i missread your post

>Declaring all of your variable at the top of a function and prior to their use is ugly
I strongly disagree. When I first stumbled upon C code, I thought to myself that it is so much cleaner and clearer to fully know in advance what to look out for.

>reading comprehension

No.

Well, fuck me I'm retarded

You can't say no here, it wasn't a question.

Yes.

Declaring variables at the beginning of the function or class is super duper better and bestest.
However, the exception to that is temporary variables such as counters that are only used immediately after.

Either way, if you're not declaring the existence of your for loop counter variable inside the for loop declaration itself for any reason other than using a counter variable that was assigned a specific value by a prior function or arithmetic assignment, go fuck yourself and/or stop using visual studios for C.

You can't know anything meaningful about those variables until you get there. There's noth9ing clean about repeatedly reassigning your loop variable, as though you're controlling what register will be used for what.

>people still unironically struggle to understand pointers
literally how?
is it the abstraction?

it's more confusing when they're implicit desu

either have referential transparency or have explicit dereferencing, otherwise it becomes a mess

I always had problems understand passing by value, passing reference and passing by pointers.

Attached: 83099351302.png (399x328, 84K)

Pointers aren't abstract. It's literally just a variable that holds a memory address. Literally, the exact same as finding a certain room number, or any one of a billion other logical tasks every human being performs constantly.

The problem is the ridiculous way programming and computer science are taught. A pointer is just a memory address. Period. What is a null pointer? A pointer that doesn't point to something you might expect. How can you tell the difference? Assign it to a common value, like 0. What is a pointer to a pointer? The address of a region of memory that holds the address to another region of memory.

Like every underlying aspect of programming, it is incredibly simple. The way it's taught is just layered with a bunch of other bullshit. Like, how many times have you seen array subscripting explained as ptr[0] == ptr + 0, ptr[10] == ptr + 10, eg mem address 15 + 10 = 25. Etc. I never have. The variable must be stored somehow, it must have a size. Therefore the pointer is the starting address of a region of memory of the size of the object. It is accessed accordingly.

Makes me real mad.

it's because programming guides fail to explain correctly how there's two versions of "=", you can copy a value from a value to a value, or you can set the very instance of a value to a value.

Did a jekyll theme for the website of the irc channel:
> dailyprog.org/♯∕g∕dpt/

>you can set the very instance of a value to a value

Attached: 1525891708311.png (229x220, 6K)

>english

Attached: 1505347978178.png (523x592, 362K)

just declare right before use with line breaks to separate blocks.
not that hard, desu.

>system breaks if username has nonascii characters
>new feature is to not allow utf-8 characters that look like others to avoid impersonating other users
Things write themselves.

just made a simple rng maze game (pic related), but, i only know how to do graphics via 'cout'ing text to a console, which makes the screen flicker a lot whenever i move. anyone have a better idea on how to handle doing this? (not looking to get into opengl/whatever yet, as im still learning)

Attached: ss+(2018-06-19+at+04.11.37).png (616x879, 12K)

you can write to the console buffer directly and even use colors:
benryves.com/tutorials/winconsole/

hey thanks a lot man, ill check that out once im back from work

Different people learn programming in completely different ways, I think some ways much more efficient than others. I think some people think about how it gets done a level or so below the code they're actually writing... Then other people just learn a bunch of surface level rules that they patch together to form a program (which happens frequently with pointers in college courses). It's obviously a spectrum, and I think we all more or less started on the retarded end and built up our skillset. But having to teach it enough times has made me believe an aspect of talent will speed you up or slow you down, which I wasn't really concerned about back when I was learning myself.

>The way it's taught is just layered with a bunch of other bullshit.
Problem is, there's a lot of things you can do with pointers. They're multi-purpose power tools. This breaks brainlets' brains.

It's my mom's fault for having me in her 40s.

Attached: 51983.jpg (303x566, 40K)

There really aren't though. It's just a variable that holds an address. If you're doing pointer arithmetic, the compiler knows the size of the type it points to and increments accordingly. It's still just an address. If it becomes something else, a cast is used, and it's just a pointer to a region of memory of a different size. Likewise for inferring the starting position of an object based on a pointer to a member, casting to void, all that.

No, I don't agree. The whole problem is that people are keen to look at something and say "there's so much, and everything is so different!", but our universe doesn't work that way. The best way to teach is to show that everything is, and is connected, in a way that is more simple than it may appear. Simple underlying logic.

If a pointer is doing something else, or is being used to hold packed values or do some rel32 stuff, as far as the language constructs are concerned it's not a pointer anymore. And anyone using those things knows what they're doing anyway.

I'm writing a simple shell as an exercise in C (and also to get more comfy with systems programming in linux), and I know there's the GNU ReadLine library to handle all those fun, terrible escape sequences and give you things like "press up arrow key to cycle history of commands"

But I wanna do it myself.
So far I have:
Echo disable, canonical mode off, full byte capture of all keypresses, I can echo back things char-for-char as I enter them in without losing my buffer, I can read newlines and parse commands out of said buffer
BUT
I can't seem to figure out how to move the cursor around, say if I hit left/right I want to be able to move forwards and backwards in the buffer.
Well, on the screen. Doing it inside the buffer is trivial.

Just as a test I'm using "\033[%d;%dH", x, y inside a printf to see what happens, and what happens is:
Nothing. Once I exit my shell however, the terminal will snap back into place on what that cursor line should have been, which seems to imply it's not being flushed to out?
I'm echoing everything back onto the screen using write(STDERR_FILENO, "string", bytesinstring), would using printf instead be causing that?

I'd hope nobody has any problems with the concept of pointers. The problems usually come in the implementation. C/C++ has a bunch of silly shenanigans when it comes to dereferencing, especially in regards to operators (take ++ as an example).
Well, that and when using pointers as a tool to perform memory manipulation shenanigans.

>C++ has a bunch of silly shenanigans
Weirdest thing in C++'s Pointer is iterator. There is tons of different type of iterator depends on their behavior, but sometimes the library maker doesn't specify what is the iterator type.
Also iterator could have more thing than the pointer, I know a library that store a std::vector inside the iterator and causing passing iterator around to be very expensive

"Iterator" is just a concept. It goes through a sequence of elements. You increment it, it goes to the next element. It stops when it compares a certain way to an "end" iterator. The internal implementation is irrelevant and might not necessarily even contain a pointer.

> The internal implementation is irrelevant and might not necessarily even contain a pointer.
In an ideal world, yes.
In a C++ world, hahahahahahahahahahahahahahahahahaha

C++ is my primary language. I'm not sure what you mean.

It means every non-STL implementation of anything anywhere written by anybody is tailor-made specifically to what they decided they needed it for, which means if youre LUCKY it's consistent with everybody elses implementation of iterators and a pointer into a collection.
Most likely it's handing you copy after copy after copy.
At worst, it's handing you copies of data that was allocated as a pointer on the heap.

>C++ is my primary language
No, it isn't. A tiiny subsection of it is "a thing you are familiar with".
The fact you haven't been around enough of it to know how fucking shittily written most iterators are is enough to show that.

dumb frogposter

stupid frogposter

Attached: 24074.png (700x775, 908K)

True, I avoid using anyone's anything that isn't just an interface to their library. My own iterators generally behave in the same way as the STL.

> how fucking shittily written most iterators are
Has little to do with the integrity of a concept. People calling something something it shouldn't be called, does not bear much relation to its actual identity.

ie, fuck people.

retarded frogposter