/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

beej.us/guide/
twitter.com/SFWRedditVideos

what is this nonsense?

Reposting because I'm absolute shit at terminal wonkery:

Trying to organize my desktop.

I'm using tags to organize images by their respective qualities. I recently downloaded the "tag" utility for the Mac terminal, and was wondering, how would I move all the files with a certain tag to a folder?

The command tag -m gray
lists all the files with a gray tag. I was wondering, given this list, how could I use the "mv" command to move all these files to a folder?

>using a mac
this is where you went wrong, 30 year old.

They want to underpay you for retard webdev. No surprise there.

Posting in new thread for discussion:

The more I understand libuv the nicer it seems. It's very consistent and functional, as far as it seems. Better than any other C/C++ boost-free netlib. How do you anons do your networking?

To be fair, given the area (both geographic and area of CS), there are a lot of really talented people from nearby universities.
Is it stupid that an internship requires 5 years of experience? Yes, but at the same time, it's a job that probably couldn't be done without the adequate knowledge base.

There are more entry-level jobs out there, though.

man xargs

...

I want to get started in network stuff, but I don't care about using libraries. I want to work with low level stuff and design network protocols bottom-up. But I don't really know how or where to start.

Corporate oligarchy.

Alright. I think I'm on the right track:

I do xargs ls* | tag -m gray

I'm reading the man page, and it appears that I can use it with another utility... How would I pass in this output to "mv"?

You can apply and still have a good chance of getting it if that's what you want. But they just look like leeches.

Would someone with 5 years experience be looking for an internship? Same for, 4? 2? 1?

That said an internship with leeches is still an internship. Just don't expect to enjoy your time there.

1. Completely outlaw C programming, seize all C books and burn, delete and shred them.
2. Rewrite everything into Rust
3. Kill C, C is communism

mv $(commandthatproducesfilenameyouwishtomove) destination
$() executes the command inside the parenthesis and inputs the output where you used it.

You already posted this and it wasn't clever, interesting, or good this time, either.

You could at least suggest a language suited to replace C.

Oh, okay. I was doing that, but without the $(), so it wasn't reading it properly... Thanks user!

C#

Rust

mv $(tag -m gray) destination

tag -m gray | xargs -0 mv $1 gray/$1

Should I learn D?

Why don't we have modern Lisp machines?

Why doesn't that faggot Paul Graham fund some?

Because he realized that Lisps are a meme when they couldn't handle HN backend.

Okay, I tried this, and two things came up:
1) I have spaces in my filenames (woops) and mv is delimiting by space, not by line, so it thinks the file "a b c" is actually three files, "a", "b", "c"

2) mv:rename is being run even though I just want to move files (though this might have to do with (1))

god bash is shit

how do you go above 10k loc without everything become a spaghettio mess?

D is pretty nice. Although it inherits some shittyness from C directly

Repostan, because the C-hating memers need to be put in their place. We need every language, but some languages are more important than some others. C is very important, not because it is an easy language (it is not), but because there is no alternative in how a language tries to capture the essence of most machines.

It's not a C issue, it's an issue of calling conventions between architectures, and even between OSes.

C defines an abstract machine, everything that is well-defined behavior in C is pretty much what all computers have in common. Calling convention is not, and it is not C goal to impose a style. That means that:
- calling convention is implementation-defined
- since you can't know beforehand how the arguments will be passed, passing arguments with side effects is undefined behavior, which is logical, because results of side-effected arguments will be inconsistent across implementations of calling convention

Of course, modern languages like Rust try to solve every undefined behavior of C by imposing a behavior, but this has one big adverse consequences: if your target environment behaves differently from what the language requires, workaround will have to be implemented either in compiler or in runtime, resulting in a less straightforward implementation than in C, with all that implies in terms of complexity and performance.

No wonder why undefined behavior exists in C. Either deal with it or trade some simplicity of implementation for simplicity of use.

how do I post code with that white background

[ code ]your code here[/ code ]

In C++

[ code ]void funtion( char *a )
{
//only reads to *a, no writes to *a
}
int main()
{
char A[] = {0,0,0};
funtion( A );
const char B[] = {1,1,1};
funtion( B );//

Apparently we're not allowed to break older versions of mobile apps by updating the security of our modern apps services. Apparently.

How is this a thing? Is it due to google play/apple being cunts?

[ code ]test[/ code ]
I can't believe you have done this to me

this is why, even if you consider them pajeet tier, you must learn markup languages like html

Pajeet please, not only you need to lurk more, but you need at least a couple of neurons to post here.

The whole android thing, being based on java is an abomination. We consumers aren't allowed to have a good OS for a smartphone.

>android dev kit shares syntax and calls with java therefore android OS is javaVM
Go to bed larry.

>implying jvm is the only thing that sucks on the java world (other than the curry odor, of course)

Good morning, anyone got a moment to help with some simple c++ shit?


vector *graph; // I have this graph.

void Graph::addEdge(int from, int to, int weight) {
for (int i = 0; i < this->graph[from].size(); i++) {
tuple edge = this->graph[from][i]; // This line is giving an error " Class vector

I mean it's that and forced objects.
Really don't see what else would affect the OS level other than shit like "wahh I dont like the way the syntax is for creating a new thread" which is a nonfactor by the time you get to implementation

change
void funtion( char *a )
to
void funtion(const char *a )

try casting it yet?

Not sure what your problem is but for fuck's sake use some typedefs or whatever.

using Edge = std::tuple;
using Edges = std::vector;
using Graph = std::vector;

void Graph::addEdge(int from, int to, int weight)
{
int size = graph->at(from).size();
for (int i = 0; i < size; ++i) {
Edge edge = graph->at(from).at(i);
}
}

Sorry senpai, new to C++ so I haven't even considered that yet. Will do right away.

>tfw c++ has something similar to Haskell's type.

Will try it out, thanks for the suggestion.

Oh also if your graph is actually a pointer are you sure you can do graph[from]? Wouldn't that just access the memory address of graph with an offset of from? So try:
(*graph)[from][i]


or:
graph->at(from)[i]

also since [] is actually an operator try to define the order of operations with (graph[from])[i]. Dont think it'd change anything but

My fucking hero, many thanks man. I don't have much experience with C++ or C in general so I'm making lots of rookie mistakes.

Will do, thanks!

Modularization.

For your "funtion", you should have the argument be a const char*, rather than just a char*. Furthermore, it is best practice to ALWAYS use const for pointer/reference arguments whenever it can be guaranteed that the argument will never be written to. You will note that the C and C++ standard libraries are replete with examples of this behavior.

But why is this a thing? A service and a client should be in updated at the same time, and require eachother to be on the same version if you want to guarantee functionality and security. Forcing someone to upgrade to continue using a service is the only way you can ensure security.

Whoever thought that limiting all work with lists to one [Head|Tail] decomposer in Prolog is a great idea is a dick. Big, big dick.
I spend most of my time on reinventing predicates to work with lists like cut out the sublist from the list, checking if all values are unique and such.

"it's like im really working on a database!"

Who are you quoting?

you, making a script to do all that.

void function(int *a)
{
a[0] = 0;
}
soo here the parameter "int *a" should be "const int *a"?

test

Yeah, welcome to Prolog. It's not intended to actually be used for anything. Just enjoy the novelty of logic programming being... different.

No.

#include

template
T f(T counter, ...)
{
T arg;
int i = 1;
va_list p;
va_start(p, counter);
T min = va_arg(p, T);

counter--;
while (i < counter){
counter--;
arg = va_arg(p, T);
min = min < arg ? min : arg;
}

va_end(p);
return min;
}


As far as I am concerned, cstdarg macros' couldn't use template correctly. If I call f(3, 1, 2,3), it shows 1 as a result, which is correct. However, if I call things like f(3, 1.1, 2, 3), considering first argument as a double, it is not working. Is there a way to work with all types of arguments?

const int * a; // pointer whose contents cannot be changed.
int * const a; // pointer that cannot be changed

Dumb sepplesfag.
You should actually learn how varargs work.

Clearly not, since you are mutating the contents of the buffer pointed to.

I don't understand.

Could you please explain the difference between

argv[][] and *argv[] ?

Why would a 2d array be the same as a pointer to a 1d array, very confusing

(speaking about the command line arguments in the main parameter in C)

An array is just a pointer to a space in memory.

You have to think about it in terms of memory. A 2d array is just many 1d arrays stacked ontop of eachother. So memory offsets 0-arrayWidth corresponds to arr[0][offset]. After that there's another array, arr[1][n] and so on.

I think the mixing of pointers and array notation is a mistake in C. You should be allowed array notation for simple 1D arrays and use pointer arithmetic for everything else.

Learn about C arrays first, starting with 1d arrays, because these are a specific beast with a non-obvious relationship to pointers. (If you remember to think low-level and about where memory resides it becomes intuitive at the end tho)

>argv[][] and *argv[]
argv[][] == *argv[] == **argv
It's all just pointers. There's no "real" dimensional arrays in the language. The multiple brackets or pointer declarations is just ways of telling you how many steps of indirection you have.

Ohh right that was painfully obvious my bad lol

>argv[][]
This is not valid in C. The inner (right) array needs a dimension.
>same as a pointer to a 1d array
This is not relevant to argv though.
*argv[] is NOT a pointer to a 1D array. It's a 1D array of pointers.

>argv[][]
As I said in : not valid.
An "array" passed into a function will decay into a pointer, but that does not work recursively.
You can't have a pointer to an array of unspecified size.

>will decay
no such thing

When am I supposed to graduate from Python to a real language?

Or should I just become webdev.

Yes there is.

beej.us/guide/

I think it does make sense. Imagine being an overeducated web dev dreaming about doing something more meaningful now. That's your entry ticket.

>1. Completely outlaw C programming, seize all C books and burn, delete and shred them.
Who's this guy?

The Linux kernel disables interrupts sometimes.
How the fuck does it do that without missing important hardware interrupts?

There are uninterruptible hardware interrupts. Look up for NMI.

>uninterruptible
*unmaskable

webdev is for pseudo-intellectuals who wear glasses without lenses

CIA nigger

I remember programming in BASIC.
It was fun and simple.
Why it's not fun to program anymore?

programming is only fun as a hobby

>tfw fell into the c++ trap

C++ traps are gay

no, there isn't

Just saying it isn't going to make it true.
The word "decay" even appears in the standard.

Does anyone here write Prolog? It's such a weird language.

>C has classes
>the word "class" even appears in the standard

What kind of webshit logic is this?

the standard says nothing decays
BTFO
T
F
O

Would

C++
>mat4::perspective(float fov, float apr) {}

be the same as

Java
>mat4.perspective(float fov, float apr) {}

If not, what does the :: mean/do?

Senpaitachi, I'm learning C++, and as recommended I'm trying to use the shell to compile the stuff, since it would teach you more about what you're doing.

But I'm doing some stuff wrong, I think.
Do I really need to link every library and every cpp file manually every time I compile, or is there an easier way for this?

And how would one go to debug the code? I'm using vim, but I assume I can't debug with vim (albeit not sure).

How do I add elements in two lists together? I need this to output [2, 6] instead of [1, 2, 1, 4]. I need to do it at the lowest level without using sum or zip.
def add_vectors(u, v):
for i in u and v:
result = u[:] + v[:]
return result
print(add_vectors([1, 2], [1, 4]))

:: is scoping, it's for when you want to refer to the function itself

haskell
zipWith (+)

:: is for static members of a class or anything inside a namespace

Not that I write everyday in Prolog, but I learned it right where it was invented (Marseille, France).

It's a very ingenuous language, conceived at first to build AIs which would talk in natural tongues. But there are too many dialects of it, the first implementation failed its commercialization and unfortunately failed to be the reference that it should have been.

I guess you could write very nice parsers in it, but it fares quite badly with low-level programming, so it pretty much has to be associated with such a fitting language for low-level tasks.

I have heard that some people actually use embedded Prolog for type inference in compilers.