[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
/dpt/ - Daily Programming Thread
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 37
File: 1461807293700.jpg (106 KB, 720x720) Image search: [Google]
1461807293700.jpg
106 KB, 720x720
old thread >>54262333

What are you working on /dpt/?
>>
First for Nichijou is fucking shit,
>>
Learning some Node.js
>>
i want to marry maki
>>
>>54267415
(You)
>>
>response to last thread user

>>54267388
After one or more of my websites at least gets me reasonable income (haven't launched them yet), I probably will program for fun.

I'd like to make some games, maybe try some apps.

I REALLY would like to try custom programming for Arduino to actually control mechanical things.
And I don't think I'd be fully satisfied until I'm at least involved in writing the next big commercial OS (obviously, based off of UNIX and fully POSIX-compliant, because that's just the smart thing to do)*

>*I actually have a limited set of POSIX commands available for Windows using "msys".
Would pick a different OS, but Windows has most of what I need and want put together. (despite being built on top of the pile of metric shite called .NET)
>>
>>54267450
I'm serious though.
It's shitty as a comedy and it's shitty as a SOL. It doesn't get anything right.
>>
>>54267474
cool opinion tho
>>
>>54267474
not him, but I enjoyed it. I even read like the first 94 chapters of the manga online.

Aioi is kawaii, though
>>
Ruby threads are a lie
>>
main.c
#include <stdio.h>
#include "balls.h"

extern int a();

int main(void) {
int i = a();
printf("%d\n", i);
return 0;
}


balls.h
#ifndef __BALLS_H__
#define __BALLS_H__
int a(void);
#endif


balls.c
int a(void) {
return 3;
}


this doesn't work for me
wat do
>>
>>54267504
You've probably got your compiler command wrong.
>>
>>54267504
you're compiling both c files, right?
>>
>>54267516
>>54267518
$gcc main.c balls.c -o main
>>
>>54267494

It's true. Same with Python. Global Interpreter Locks are shit.
>>
>>54267520
What is the error that it gives then?
>>
>>54267533
I think it's implied that anything beyond toy programs are shit in scripting languages
>>
>>54267504
Why are you using extern on that. You're including the header in the main() file.

It's already defined there.
When you include the file, it basically copies it where it's included.

you also don't need to use void in the argument parameter. That's just unnecessary

And this program doesn't really look big enough to require ifndef, because I doubt you'll be including it a ton of times.

I also think the issue might be because extern int a() does not match int a(void)
Might work if you remove void (or add void to extern)

balls.c also needs to include balls.h
>>
>>54267548
all valid points, but it should still compile and work
>>
>>54267569
Well, try including balls.h in balls.c

farlin 500 north
>>
>>54267548
>you also don't need to use void in the argument parameter. That's just unnecessary
For the prototype, it actually makes a difference. () is unspecified arguments, (void) is no arguments.
If it's empty, the compiler cannot do any type checking on it.
>I also think the issue might be because extern int a() does not match int a(void)
They are compatible, because of above.
>balls.c also needs to include balls.h
It's good practice, but not strictly necessary.

>>54267504
A compiled and ran your code verbatim, and it worked as expected for me.
>>
>>54267605
>It's good practice, but not strictly necessary.
any non-trivial program will make it necessary because balls.c probably has structs that are used by the rest of the program and so are declared in balls.h
>>
>>54267691
Yes, I'm not saying that he shouldn't do it, in fact I agree with you that he should. It's just that it's possible for him not to.
>probably has structs that are used by the rest of the program and so are declared in balls.h
He COULD redeclare them.
>>
File: japanimebymichaelbay.webm (3 MB, 864x480) Image search: [Google]
japanimebymichaelbay.webm
3 MB, 864x480
Ask your elegant and much beloved programming literate anything (IAMA).

>>54267494
Threads being native or green is implementation dependent (JRuby, Topaz, and Rubinius have native threads)

>>54267533
A GIL has benefits.

http://pyparallel.org/

>>54267543
What's a scripting language ?
>>
>>54267533
same in OCaml at the moment~
>>
>>54267733
you fucking slut
>>
Want to make an apk that installs assets to a specific path on internal disk.

Code looks like this so far

//MAIN ACTIVITY
package com.anon.expansionpacks
import android.app.*;
import android.os.*;
import java.io.File;
import android.opengl.GLSurfaceView;

public class MainActivity extends Activity
{
File file = new File(context.getFilesDir(), filename);
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
>>
>>54267722
scripting language there is being used to refer to dynamic high-level general-purpose languages
>>
It's kind of shit how dynamic statically typed languages are the future
>>
>>54267811
strongly typed, rather
>>
>>54267811
>dynamic statically typed
That's a contradiction of terms.
>>
>>54267811
You're seeing it wrong, anon. Dynamic languages will come and go. (Forefronting) Statically typed languages will always have their place, however.
>>
File: 2016-04-28 02_31_17.png (121 KB, 1505x992) Image search: [Google]
2016-04-28 02_31_17.png
121 KB, 1505x992
Exploring how collective pitch, forward speed, tilt angle, etc. affect the thrust produced by a quadrotor I'm designing. neat stuff desu
>>
>>54267959
Cool stuff m8. Designing professionally or hobby?
>>
I've got 3 weeks after exams before I start working.

What new language should I learn?

I already know C,C++,Java,C#,Elixir.
>>
>>54268142
Any scripting language; JS, Python, Ruby are the big ones right now. I personally like Lua but they are all extremely similar languages.
>>
File: logging.png (26 KB, 583x388) Image search: [Google]
logging.png
26 KB, 583x388
is there a prettier way to do logging?
>>
File: 2016-04-28 03_12_30.png (38 KB, 1086x632) Image search: [Google]
2016-04-28 03_12_30.png
38 KB, 1086x632
>>54268086
Senior design project. Also a hobby once I'm outta school and have time for hobbies. Or professionally if anyone wants to hire me.
>>
>>54268239
Use can use the return value from sprintf instead of calling strlen.
>>
>>54267409
Why does printVariablesAndLengths() never work? It just returns -1.

/*

b. Implement a program in another file, which:
i. Receives a string from the user as an argument;
ii. Stores the characters of your student number one by one in a char array variable;
iii. Prints the above two variables and length of strings (from i and ii), using one printf() statement; and
iv. Includes examples to test the above 3 functions, with proper assignments and printf() statements.

*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char s;
char arr[9];

void getString()
{
char *s = (char*) malloc( 100 );

if (s == NULL)
{
printf("Not enough memory to allocate buffer.\n");
exit(1);
}

printf("Please input a string.\n");
gets(s);
}

void getStudentNumber()
{
printf("Please input your student number.\n");
int c;
int count;
c = getchar();
count = 0;
while (count < 9 && (c != EOF))
{
arr[count] = c;
++count;
c = getchar();
}
}

void printVariablesAndLengths()
{
printf("The string is %s and the student number is %s. The string is %d characters long and the student number is %d characters long.\n", s, arr, strlen(s), strlen(arr));

}

int main()
{
getString();
getStudentNumber();
printVariablesAndLengths();

return 0;
}
>>
>>54268364
>char *s = (char*) malloc( 100 );
This "shadows" the variable s. Any changes to s in this function will NOT affect the global version of s.
>gets(s);
Just no.
>printf("...", s, arr, strlen(s), strlen(arr));
You've declared s as a single char, not as a string.

Here is basically how you fix your code:
Replace
char s;
with
char *s;

Replace
char *s = (char*) malloc( 100 );
with
s = malloc( 100 );

This will stop you shadowing the global variable and declare s as the correct type.
>>
>>54267409
Is OpenCV a good choice to do image recognition in C ?
>>
>>54268395
That fixed it. Thanks.

When I use scanf instead of gets it just breaks everything.
>>
>>54268431
Use fgets.
>>
>>54268411
It's better than making your own image parser
>>
>>54268239
C++

>>54268142
F# if you want something different
>>
File: chandown.png (109 KB, 1901x967) Image search: [Google]
chandown.png
109 KB, 1901x967
Currently working on a 4chan thread watcher. I am a total fucking hack but so far I can add url's and it will automatically scan and download all images on each url every interval. Got a lot more to go to tidy it up and give it the features I want it to have. Learning a lot making it but holy shit I wish I knew how to code properly and in a decent language.
>>
>>54268458
>visual basic

Anon step it up pls this thread is for adults
>>
>>54268458
is this real
>>
C++ question:

class A
{
float (A::*func)(float);
float foo(float x);
float setFunc() {
func = &A::foo; //seg fault
}
};

It's all compiling fine, why won't am I getting segmentation faults when I try to set my member function pointer to a member function of the same class?
>>
>>54268458
Just kill yourself doode
>>
>>54268471
You forgot your return statement.
>>
>>54268458
>I wish I knew how to code properly and in a decent language.
it's not something you just wish for, just fucking learn it stupid cunt
>>
>>54268482
kek, not him and even I didn't notice that
>>
>>54268482
>>54268471
oh sorry, that's a typo, setFunc should be void, also foo is declared before you ask
>>
>>54267409
I am trying to make a program that copies one file into another file using file name inputs from the user. I found a program that works from the command line like "cp fileA fileB" and now I am changing it to work for me. I don't really get how I am going to change the file descriptors from integers to chars. How am I going to get it to use file names?

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
#include <unistd.h>

#define BUF_SIZE 8192

int main(int argc, char* argv[]) {

int input_fd, output_fd; /* Input and output file descriptors */
ssize_t ret_in, ret_out; /* Number of bytes returned by read() and write() */
char buffer[BUF_SIZE]; /* Character buffer */

printf("Please enter two file names. The first one will be copied into the second one.\n");
printf("First file: \n");
gets(input_fd);
printf("Second file: \n");
gets(output_fd);

/*
/* Are src and dest file name arguments missing *
if(argc != 3){
printf ("Usage: cp file1 file2");
return 1;
}
*/


/* Create input file descriptor */
input_fd = open (argv [1], O_RDONLY);
if (input_fd == -1) {
perror ("open");
return 2;
}

/* Create output file descriptor */
output_fd = open(argv[2], O_WRONLY | O_CREAT, 0644);
if(output_fd == -1){
perror("open");
return 3;
}

/* Copy process */
while((ret_in = read (input_fd, &buffer, BUF_SIZE)) > 0){
ret_out = write (output_fd, &buffer, (ssize_t) ret_in);
if(ret_out != ret_in){
/* Write error */
perror("write");
return 4;
}
}

/* Close file descriptors */
close (input_fd);
close (output_fd);

printf("The first file has been copied into the second file.\n");

return (EXIT_SUCCESS);
}
>>
>>54268491
>>54268495
I was trying to fuck with him. I have no idea if that was the problem
>>
>>54268510
should've said that it should be return foo = &A::foo;
>>
>>54268510
>>54268517
I should've known better than to come here during aussie hours.
>>
>>54268524
You mean during american NEET hours
>>
>>54268524
Maybe you can't have a pointer to a function of an unfinished class
>>
>>54268471
dood why are you trying to resolve the scope of a variable if you're already in the class? Take that out and try again.
>>
>>54268509
>int input_fd
>gets(input_fd);
For starters, don't ever use gets. Use fgets.
Also, you cannot read an integer like this. (f)gets reads strings, hence the name "GET String".

It would be easier to do that from scratch than try to adapt that program.
Just use fgets to get two file names, and use them both with fopen. Then read and copy from one file into the other.
>>
>>54268509

it already does. open() returns the int.

how are you trying to change this program, exactly? what's wrong with how it works now?
>>
>>54268554
I'm not allowed to use any of the FILE functions like fopen.
>>
>>54268571
What sick fuck gave you that restriction?
>>
>>54268564
It doesn't compile yet.

Right now it has to get file names from the command line, but it is required to get them from a prompt.
>>
>>54268575
his mum
>>
>>54268575
My instructor.
>>
>>54268553
then it doesn't compile, if you need the scope in the assignment of a member function even if you're in the scope when you assign it, the function pointer of course needs the same scope then as well (A::*).

>>54268550
I'm honestly not 100% sure what you mean by "finished." My actual code has a default constructor and destructor, but those should've been generated automatically if needed even if I didn't.
>>
>>54268584
Is his name Pajeet perhaps?
>>
>>54268588
I mean like how you can't do

class A{
A x;
}
>>
>>54268591
Yes. His name is Pajeet Singh and he loves watching white boys suffer so he forbade me from using the FILE functions.
>>
>>54268602
hmm. you're probably right. I'm surprised this compiled (g++ 5). really makes what I'm trying to do a lot more difficult....
>>
why do the graphics look so shitty? is the gamma fucked?

https://www.youtube.com/watch?v=g24fkMZMshk
>>
int f(const char *c){...}

f ( (std::string("str") + std::to_string(somevar)).c_str() );


Is it okay to construct strings in place like that? Will the pointer be valid until f() returns?
>>
>>54268697
>fat cuck sjw video game reviewer
Please don't link things this cancerous.
>>
>>54268779
>being this triggered
the graphics look exceptionally shitty, just wondering if it's what i think it is, no gamma correction and then they've fucked with the colors and lighting to try to make up for it
>>
>>54267794
>scripting language are general-purpose languages
k, tard
>>
>>54268858
i hope you fuck off more than you do your wife, jim
>>
>>54268883
what
>>
>>54268866
Want to classify them any differently? They aren't OOP or functional.
>>
I'm a beginner, learning Python.
My code was working great before moving them into functions (for re-usability). Each function was originally a sequential section of code which did not rely on other sections except a few variables being used globally. The problem is the variables do not seem to be seen to the rest of the program and now throw an error, when they were defined just fine before being put into a function. I know what the problem is, but I don't know how to fix it. These variables are generated within the functions. I've included a simplified version of the program.

The error:

Traceback (most recent call last):
File "D:\Programming\code.py", line 158, in <module>
parseFile()
File "D:\Programming\code.py", line 66, in parseFile
for line in contentSubmissions.splitlines():
NameError: global name 'contentSubmissions' is not defined


The (simplified) code:

def importLocalFile():

fileSubmissions = open('submissions.html', 'r')
contentSubmissions = fileSubmissions.read()

def parseFile():
numberOfSubmissions = 0

for line in contentSubmissions.splitlines():

#code to generate items

tableList.append((column1, column2, column3))
numberOfSubmissions += 1

def printFile():
if numberOfSubmissions == 0:
print "No Submissions"
else:
#code to generate and display table

importLocalFile()
parseFile()
printFile()
raw_input("\nPress enter to quit...")
>>
>>54268960
You've just discovered why weakly typed dynamic languages are cancer. Try initializing contentsubmissions in the global scope before assigning
>>
>>54268960
>>54269015
I just noticed you have idented your initial variables. Python uses forced identation scopes (which is also fucking cancer) so I suggest you take out those spaces.
>>
File: downvote.webm (284 KB, 1400x788) Image search: [Google]
downvote.webm
284 KB, 1400x788
>>54267794
A scripting language is _when_ a programming language is being used to extend a specific program and is dependent to that program.

>>54267821
Not really.

>>54268960
def importLocalFile():
fileSubmissions = open('submissions.html', 'r')
global contentSubmissions # **FIX **
contentSubmissions = fileSubmissions.read()


>>54269015
That's an issue about namespaces here, not an issue about typing. And even that, python is not weakly typed (contrary to C which is statically typed).
>>
>>54269077
C isn't weakly typed, Python is
>>
>>54269109
prove it
>>
>>54269130
The users of python are weak at typing
>>
>>54269130
You're the one who made the claim, idiot.
>>
>>54269130

C:
int x = 3;
x = 'x'; // x is an int

Python:
x = 3; // x ""is an int""
x = 'x'; // x ""is a char""
>>
>>54269157
you just wrote that python is weakly typed. prove it.
>>
>>54269171
That's not weak typing, idiot!
>>
>>54268772
Why wouldn't it? The string lifetime coincides with the callee function, not the caller.

This code is valid and pretty much the same as yours:
void f(const char *s)
{
std::cout << s << std::endl;
}

int main(void)
{
const char *s;
f( (s = (std::string("str") + std::to_string(10)).c_str()) );
std::cout << s << std::endl;
}


While this sample causes undefined behavior because the string has been unstacked when returning from get_string:
void f(const char *s)
{
std::cout << s << std::endl;
}

const char * get_string()
{
const char *s = (std::string("str") + std::to_string(1)).c_str();
return s;
}

int main(void)
{
f(get_string());
}
>>
>>54269193
>type of a variable changes
>strongly typed
>>
>>54269077
>global contentSubmissions # **FIX **
Thank you. I got the needed variables globally defined and now it works just as it did before. I am guessing that anything defined outside a function is global by default?
>>
ive been up for 27 hours and i dont know why my code isnt working, its due in in less than 2 hours, pls help

its in swi-prolog

agent():-
percieve(Percepts),
action(Percepts),
agent().

percieve(Percepts):-
write('please enter text: '),
read(Percepts).

action(Sentance):-
member(Item, Sentance),
member(Item, [q, quit, end, stop, halt]).

action(Sentance):-
sentance(Sentance, Parsed),
write(Parsed).

sentance(Sentance, sentance(vp(Verb_phrase)) ):-
vp(Sentance, Verb_phrase, _).

sentance(Sentance, sentance(noun_phrase(NP), verb_phrase(VP)) ):-
np(Sentance, NP, Remainder),
vp(Remainder, VP, _).

np([Current | Tail], np(det(Current), NP2), Remainder):-
det(Current),
np2(Tail, NP2, Remainder).

np(Sentance, Parsed, Remainder):-
np2(Sentance, Parsed, Remainder).

np(Sentance, np(NP, PP), Remainder):-
np(Sentance, NP, Rem_np),
pp(Rem_np, PP, Remainder).

np2([Current | Tail], np2(noun(Current)), Tail):-
noun(Current).

np2([Current | Tail], np2(adj(Current), Rest), Remainder):-
adj(Current),
np2(Tail, Rest, Remainder).

pp([Current | Tail], pp(prep(Current), Parsed), Remainder):-
prep(Current),
np(Tail, Parsed, Remainder).

vp(Word, vp(verb(Word)), Remainder):-
verb(Word).

vp([Verb, Adverb | Tail], vp(verb(Verb), adverb(Adverb), Parsed), Remainder):-
verb(Verb),
adverb(Adverb),
np(Tail, Parsed, Remainder).

vp([Verb | Adverb], vp(verb(Verb), adverb(Adverb), Parsed), Remainder):-
verb(Verb),
adverb(Adverb).

vp([Current | Tail], vp(verb(Current), Parsed), Remainder):-
verb(Current),
np(Tail, Parsed, Remainder).

vp([Current | Tail], vp(verb(Current), Parsed), Remainder):-
verb(Current),
pp(Tail, Parsed, Remainder).
>>
>>54269177
def memes(arg):
print(arg)

memes(1)
memes("a")
>>
>>54269225
Yes
>>
>>54269211
>The string lifetime coincides with the callee function, not the caller.
I'm a retard, I mixed up caller and callee here. Automatic local variables have the lifetime of the CALLER, not the callee.
>>
File: wdsa.webm (483 KB, 960x540) Image search: [Google]
wdsa.webm
483 KB, 960x540
>>54269216
>>54269251

Weak typing is not about dynamic typing, it's about if you can circumvent the type system or not, it's when you "break" it. Here an example in C

char b[4] = {'a','b','c','d'};
float *f = b;


The contract that *f is a float and that f is a pointer to float is broken. The the soundness of the type system is no more guaranteed, the type system is considered weak.
>>
>>54269251
nice proof. Here's proof haskell is weakly typed:
fn x = print x

main = do
fn 42
fn "fuck my shit up"
>>
>>54269316
>float *f = b;
Dereferencing that is undefined behaviour. C has something called the strict aliasing rule.
>>
>>54267605
What does unspecified arguments mean? What does it change.
>>
>>54269339
compiler doesn't prevent it from compilation
>>
>>54269329
>print
b-b-b-but I thought Haskell was pure!
>>
>>54269339
We are talking about the type system, not about run time effects. C being statically typed, the type system is effective only during the compilation
>>
>>54269329
But 'x' is the "Show" type.

>>54269345
It means that there is no information given about the types.
calling
int fn();
like
fn();
fn(1, "a");
fn(NULL);

are all 'valid' (not really) to the compiler.

>>54269350
That doesn't mean shit. If something is undefined behaviour, it's not valid C.
>>
>>54269356
don't worry this won;t compile in a fully standard-complying compiler
Error: attempted to compile a program with side-effects. You are not suited to program in haskell. Please leave. 
>>
>>54268883
no you fuck off to >>>/vg/agdg fucking ridiculously butthurt shitter

don't get so emotionally invested in a game you clearly put very little effort into or you're just a beginner ffs
>>
>>54269363
Show is a type class, not a type. x still can be a fuckton of different types, as long as they implement Show. And the point was that your proof is shit, not to compare haskell type system to python's. Python is obviously dynamically typed.
>>
>>54269415
>Python is obviously dynamically typed
I know. I thought we were arguing about weakly typed.
Honestly "strong" and "weak" typing are so poorly defined that you could probably argue that anything is strongly or weakly typed.
>>
A C question: What is the best way to call and write functions? Now, this may seem super basic, but I'm pretty new to C. So here are four options that might be considered (and probably some in betweens):

// Option #1
double fnct ( const double a, const double b )
{
double val;
/*
calculation
*/
return val;
}
// […]
double c = fnct ( a, b );

// Option #2
double fnct ( const double *a, const double *b )
{
double val;
/*
calculation
*/
return val;
}
// […]
double c = fnct ( &a, &b );

// Option #3
double* fnct ( const double *a, const double *b )
{
static double *val = ( double * ) malloc ( sizeof(double) );
/*
calculation
*/
return val;
}
// […]
double *c = fnct ( &a, &b );

// Option #4
void fnct ( const double *a, const double *b, double *c )
{
/*
calculation
*/
}
// […]
double *c = ( double * ) malloc ( sizeof(double) );
fnct ( &a, &b, c );
// or
double c;
fnct ( &a, &b, &c );
>>
>>54269363
>it's not valid C
a compiler of a strongly typed language should not compile invalid programs in that language

>>54269446
> I thought we were arguing about weakly typed.
Not with me. I was just pointing out that the proof wasn't a proof of anything. And somehow got way too involved.
>>
>>54269458
They're all valid. It really depends on the situation for which one to use though.
It's really up to you to decide which one is best for which situation.

However, between the 3rd and the 4th one, I would pick the 4th one if you can. It gives the user more control to how the result is allocated (on the stack, malloc, inside an existing array etc.), but there are situations where you can't avoid the 3rd one (opaque types etc.)
>>
>>54269226 someone please help, in addition to a few warnings i appear to be stuck in a loop where i can fully parse the sentance but not make it back out again
>>
>>54269510
So, does it give me an advantage if I do
function ( const double *a )
instead of 

function ( const double a )

or is the difference made irrelevant by today's compilers anyway?
>>
>>54269554
Only do the first if you're taking an array of doubles as input. I don't exactly know the performance characteristics of it, but there is no reason to have a pointer to a single element unless you plan to write to it.
I was more talking about outputs before.
>>
>>54269458
#1 and #4 are good
>>
>>54269599
or in #4 change it to
void fnct ( const double a, const double b, double *c )


primitives are small enough to pass by value, only use indirection when it's needed or when you have structs or arrays that you don't want to copy for performance reasons
>>
File: cake.webm (447 KB, 900x506) Image search: [Google]
cake.webm
447 KB, 900x506
>>54269554
_function (const double a, const double b);

#define function(x, y) \
_function(_Generic(x, const double *: *x,\
const double : x),\
_Generic(y, const double *: *y,\
const double : y))
>>
>>54269510
>>54269577
>>54269599
>>54269635
Thanks, that cleared up a lot

>>54269654
I'm not even sure what this is supposed to do
>>
>>54269715
>I'm not even sure what this is supposed to do
It's a fancy C11 feature, which will select some text based on the type of the argument.
The way he's used it is very silly though.
>>
>>54267504
>this doesn't work for me
k tard
Error message or fuck off and kill yourself.
>>
>all these retards learning C
It's like you want to be NEET.
>>
>>54270078
calm down ragefag
>>
>What are you working on /dpt/?
Just finished making a really hacky script that sets up all the di.fm stations in to a database compatible with Lollypop's radios.db so that I could import everything with the proper art without it being incredibly tedious.
>>
Help me cfags:
What do I use in C for writing games instead of inheritance polymorphism etc?
>>
>>54270306
>Inheritance
>polymorphism
>etc

Even if you're using C++ or other POO languages only retards do that for game entities.
>>
>>54270326
What then?
>>
>>54270365
Composition usually through some form of ECS.
>>
File: furiouslyembarrassed.webm (117 KB, 960x540) Image search: [Google]
furiouslyembarrassed.webm
117 KB, 960x540
>>54269767
>is very silly though
Why ?
>>
>wpf maxwidth is not in pixels but in points
>>
>>54270419
>what is dpi scaling
>>
>>54270326
Not really, inheritance vs composition is still a debate. For example, halo games are still inheritance oriented but the development time is quite good.
>>
>>54270419
Probably the best design decision microsoft has ever made.
>>
>>54270414
It unnecessarily hides details from the programmer and only works with const doubles and not regular doubles.
>>
>>54270440
>>54270450
it fucks up my resize on double click, gotta work around it...
>>
>>54270460
>It unnecessarily hides details from the programmer

well, that's point of having macros.
>>
>>54270497
Hiding whether some pointer has been dereferenced is truly shitty.
It's just as bad as the fags who typedef pointers.
>>
>>54270497
the point is to save work (the "manual labor" of editing the code), not hide details
>>
>>54270445
it isn't a debate anymore, this shit has been settled a decade ago
>>
>>54270483
you're doing it wrong
>>
>>54270638
how am i suppose to do it then?
>>
what are you even talking about with composition vs inheritance. the components themselves still need inheritance/polymorphism. even if it's just a function pointer or something it's still a kind of polymorphism.
>>
is there a modern "digital" version of K&R that looks better than the seemingly scanned PDF i found?
>>
>>54270714
try libgen
>>
File: dogi.jpg (351 KB, 1200x900) Image search: [Google]
dogi.jpg
351 KB, 1200x900
/dpt/ I need your help. I'm retards and teacher too but he makes retard assignments that retard me can't do. I shit myself everytime there is something to print images using ASCll. I can make programs to do math and engineering but I literally can't get my head arround asterisk triangles, diamond and shit.


The assignment is as it follows:
Make a program that creates and stores in a 2D array the matrix bellow, using only arrays and loops. The array shall have a size of 3x3 through 20x20 and the decision should be given by the user.
1 1 0 1 1
1 0 0 0 1
0 0 0 0 0
1 0 0 0 1
1 1 0 1 1


So far my retard mind has:
/*do that shit*/
int i, j, k, lin, col,
printf("Please enter the number of lines and columns\n");
scanf("%d %d", &lin, &col);
int mat[lin][col];
}
/*Prints that shit*/
for(i=0;i<lin;++i)
{
for(j=0;j<col;++j)
printf("%d", mat[i][j]);
printf("\n");
}
}
>>
>>54270705
>the components themselves still need inheritance/polymorphism
No they don't.
>>
>>54270680
nevermind, i was over complicating it
>>54270638
thanks tho
>>
>>54270729
Basically to print a diamon using arrays. pls send help
>>
>>54270730
yes they do, you compose an object using components that are used in the same way, like different types of weapons that can act as a weapon component, it's polymorphism
>>
File: ss+(2016-04-28+at+03.09.26).png (103 KB, 1661x744) Image search: [Google]
ss+(2016-04-28+at+03.09.26).png
103 KB, 1661x744
>>54270719
what's the canon one? number of pages seems to differ wildly.
also any difference between "the ansi C programming language" and "the c programming language"?
>>
>>54270756
>ansi C
deprecated shit, even more deprecated than "modern" standardized C
>>
>>54270763
K&R C is also deprecated
>>
Workin' on an UDP multicast server which sub to another server, receive the datas and parse them before sending them to a video decoder.
>>
>>54270755
inheritance is just a kind of polymorphism
polymorphism in general isn't bad, nobody ever said that
even stuff that allows you to construct type hierarchies and construct type groups isn't bad, as long as no actual behaviour is involved
inheritance is shit because behaviour can be overriden, which can easily fuck up type hierarchies constructed using inheritance.
>>
>>54270755
No you compose an object out of components, which are nothing but sets of data that is then acted upon by systems.

At least in an ECS. You certainly CAN use polymorphism with composition but it's not a hard requirement.
>>
>>54270739
nevermind again, this causes new problems, would it be so easy
>>
#ifndef ACTOR_H
#define ACTOR_H

#include "rendering_component.h"

typedef struct
{
rendering_component *rc;
} actor;

actor * actor_init(const char *image_path, SDL_Renderer *ren);
void actor_render(actor *act);
void actor_destroy(actor *act);

#endif /* ACTOR_H */


Anything wrong with this?
>>
>>54270885
>SDL
>>
>>54270904
replace SDL with anything else, is this a good architecture/design?
>>
>>54270913
looks ok but it's not much of an architecture, just a few functions and a struct
>>
i'm not finding much useful on entity component systems, just shitter tutorials and jewnity shit
>>
>>54270961
i'm just a C++ guy looking to disavow and embrace the warm holy light of C.

basically: define data structures, and then define functions that operate on those data structures?

so instead of
 structure.foo(...) 
it's
 foo(structure, ...) 
?
>>
>>54271018
yes that's what you do in C, in C++ it's syntactic sugar for the same thing
>>
https://play.google.com/store/apps/details?id=eu.depa.captionr

Mine
>>
Ok anti-C faggots, riddle me this:

if C is deprecated then what do you use to write bug-ridden toy programs and appear elitist at the same time?
>>
>>54271036
not really.
>>
>>54271095
I write in assembly then. Why should I care about portability after all? I only program for myself. :^)
>>
>>54271095
R U S T
U
S
T
>>
File: ss+(2016-04-28+at+03.47.42).png (66 KB, 970x719) Image search: [Google]
ss+(2016-04-28+at+03.47.42).png
66 KB, 970x719
Why isnt .epub more popular?

This shit is way better than pdf for reading technical books etc
>>
>>54271103
It's syntactic sugar for struct.fun(&struct, ...);
you can just assign function pointers in your struct if you care about polymorphism
>>
>>54271162
i used to love .chm books
>>
>>54271175
>>54271162
oh fuck , i meant .chm, i'm a retard
>>
>>54271162
>K&R
STOP
>>
File: haskelel2.jpg (745 KB, 1920x1080) Image search: [Google]
haskelel2.jpg
745 KB, 1920x1080
>>54271095
haskell
>>
>>54271167
>you can just assign function pointers in your struct if you care about polymorphism
Which is very different (Read Cook or Cardelli). What he done here is not an object but just a data type. No doubt OOP is considered bad with such illiterate guys like you.
>>
So I have wasted 3 days wondering what is wrong with my code
tried 100 things remade algorithms 100 times in different ways.
turns out I renamed one of the most important list variables.
how stupid am I? I should learn to give my variables good names instead of A, B, C, A1, ABA3 etc.
>>
>>54271220
it's C's version of an object. there are also functions (methods) that work on the struct (object), just that you have to explicitly pass the struct ("this") pointer instead of the method syntax
>>
>>54271220
Objects are data combined with methods that operate on said data.
What he just did is exactly that.
It's still object oriented, since the inner working of the object is hidden from the calling code.
It's even better in that regard than regular C++ code since he can decide to make the pointer opaque, and the user won't even know what's in the object, as opposed to C++ that requires you to expose the content.
>>
the optimal length of a name is proportional to its scope and inversely proportional to how often it is used and the amount of context given to understand the meaning of the name
>>
Potential project I could do for my final year next year involves scanning a standard 1:50000 and writing code to output all the contour data to a file

Would this be as simple as it seems? When I say simple I mean hours and hours of actual work but nothing explicitly difficult.
>>
>>54271269
>>54271342

You guys are completely wrong, it's embarrassing. An object is both a data and a implementation abstraction technique. The data is hidden under a set of procedures and the implementation is hidden under a procedural interface. Contrary to a data type, an object embed its procedural interface. A fully encapsulated data type is know as an abstract data type (ADT).

You can have ADTs in C but not objects.

https://www.cs.utexas.edu/users/wcook/papers/OOPvsADT/CookOOPvsADT90.pdf

>>54271342
You are confusing method with procedure.
His object is not even encapsulated, there just a small procedural abstraction for creation/destruction.

>as opposed to C++ that requires you to expose the content.
Not really. Read a C++ book.
>>
Thank god people write applications in C#, everything is so easy to crack. 90% of the time you just have to find "LicensingManager" or something and make Verify() return true. 10 lines with Mono.Cecil.
>>
>>54271421
it does the same thing as an object, it's as close to an object as you can get in C
>>
File: hes_retarded_right.jpg (12 KB, 326x154) Image search: [Google]
hes_retarded_right.jpg
12 KB, 326x154
Which is better?
enum directions {
left,
right,
above,
below
};
int value[4];
values[above] = 1;
etc...

OR
struct direction {
int left;
int right;
int above;
int below;
};
direction.left = 3;
etc..
>>
>>54271421
He can't manipulate the data without the functions that manipulates it.
Opaque pointers.
>>
>>54271453
>left > right
>>>/trash/
>>
>>54271256
a2b2, r2d2 and c3po are already taken
>>
>>54271461
it's a plain definition, retard (>>54270885)

being opaque would turn the data type into an adt, not an object.
>>
what kind of programs could i do with c++ that i cant do with python?
>>
>>54271453
give usage scenario
>>
>>54267959

what kind of jobs could a project like this get you?
>>
>>54271557
Say, I want to store a value for a node so it knows it neighbors in a graph. Does it really matter for the usage scenario? Does one provide better compiler optimisations or the other improve readability and extensibility?
>>
>>54271593
wheres your trip homeboi
>>
>>54271453
I would probably go with the struct version.
>>
>>54271648
or even a union version
>>
>>54271510
lol good one
>>
>>54271668
like this?
struct direction {
union {
char up;
char down;
char left;
char right;
};
};
>>
>>54271634
lol, I was just testing a tripforce.
>>
>>54271648
>>54271668
Well, I am using openMPI, so I went with the array because I think it is easier to do stuff with arrays because then I can iterate through the values to broadcast things to neighbours.
>>
>>54271731
union direction {
struct {
int left;
int right;
int above;
int below;
};
int array[4];
}

Best of both worlds.
>>
>>54271778
I don't know much about unions, except that they hold different objects within them.
>>
>Reading through uses of C11 _Generic
>Can use it to implement default arguments with relatively simple preprocessor code
>Even can check if too many arguments are provided
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>

struct _def;
#define DEF ((struct _def *)NULL)
#define IF_DEF(arg, def) _Generic((arg), struct _def *: def, default: (arg))

#define END_ARG DEF
#define IS_END_ARG(arg) _Generic((arg), struct _def *: true, default: false)

int foobar(int a, int b, int c, int d)
{
printf("%d\t%d\t%d\t%d\n", a, b, c, d);
}

#define foobar(...) foobar_(, ##__VA_ARGS__, DEF, DEF, DEF, DEF, END_ARG)
#define foobar_(_, a, b, c, d, end, ...) \
do { \
static_assert(IS_END_ARG(end), "too many arguments to foobar"); \
(foobar)(IF_DEF((a), 999), IF_DEF((b), 999), IF_DEF((c), 999), IF_DEF((d), 999)); \
} while (0)

int main()
{
foobar();
foobar(1);
foobar(1, 2);
foobar(1, 2, 3);
foobar(1, 2, 3, 4);
foobar(3, DEF, 3);
// Fails to compile
//foobar(1, 2, 3, 4, 5);
}

999    999    999    999
1 999 999 999
1 2 999 999
1 2 3 999
1 2 3 4
3 999 3 999

Neat.
>>
>>54271819
.array[1] is the same variable as .left, .array[2] is the same as right, etc.
It allows you to iterate over all of them easily, but still allow struct accesses with meaningful member names.
>>
>>54271843
Nice. What is array[0] though? I never really understood array that well.
>>
>>54271850
The union member that I happened to name 'array'. You can use it just like you would any other array.
>>
>>54268471
#include <functional>
#include <iostream>

struct A
{
std::function<float(float)> func;
float foo(float x)
{
return 0;
}

void setFunc()
{
func = std::bind(&A::foo, this, std::placeholders::_1);
}
};

int main(int, const char **)
{
A a{};
a.setFunc();
std::cout << a.func(5) << std::endl;
return 0;
}
>>
File: this_guy_knows_his_shits.png (176 KB, 200x200) Image search: [Google]
this_guy_knows_his_shits.png
176 KB, 200x200
>>54271859
Okay, thanks senpai.
>>
>>54269226
>>54269532
It's not working because you misspelled Sentence and Perceive
>>
File: wew.png (9 KB, 574x61) Image search: [Google]
wew.png
9 KB, 574x61
wew lad
>>
>>54272086
why would you not just raise to the power -1 ?
>>
>>54272086
so what

>>54272116
can obviously be less efficient and less convenient to use
>>
>>54272086
>>54272168
are you referring to
>this routine will divide by zero
yeah that sounds fucking retarded but maybe they defined what dividing by zero is in the context of their library
>>
>>54271859
So to get my knowledge about this correct, union creates a section in memory where either a structure or array can live. Since the structure and the array can contain 4 integers, they are the same size. Thus, whenever you access the variables with the array, you are accessing the different members of the structure because the displacement between members in the structure is the same as the array.
>>
>>54272086
People who claim that operator overloading is bad should spend a week with GMP.
>>
>>54272201
using big nums is a special thing that you should use very little if at all, and it should be treated as a very special thing that requires function calls, not just something you use ordinary O(1) operators on.
>>
>>54272086
1/0 = 0
>>
>>54272241
1/0 = +Infinity
>>
>>54272116
mpq stores rationals like a/b and not the actual value

>>54272180
yeah I chuckled when I saw it, wanted to share

>>54272218
I'm studying cryptography

>>54272241
oh you madman
>>
>>54272218
>using big nums is a special thing that you should use very little if at al
many programming languages have big nums has the main number data type.
>>
>>54272478
*shitty scripting langs
>>
>>54272510
no, i am referring to general purpose programming languages.
>>
>>54272526
>C
>C++
>java
>C#
>D
>rust
>none of the above
kill yourself
>>
>>54272273
>I'm studying cryptography
so then the bignum number crunching is a central part of the program's logic, it's not weirder to use function calls for it than to use function calls for game logic and whatever
>>
>>54267415
>>54267474
0/10, try harder.
>>
((lambda (f) (f f 1)) 
(lambda (f n) (if (= n 100) (display "Buzz")
(begin ((lambda (x)
(cond ((and (= (remainder x 3) 0) (= (remainder x 5) 0))
(display "Fizz Buzz"))
((= (remainder x 3) 0)
(display "Fizz"))
((= (remainder x 5) 0)
(display "Buzz"))
(else (display x)))) n)
(newline)
(f f (+ n 1))))))
>>
Is there a book/tutorial in python with this format?

>Brief Explanation about topic
>Sample code with explanation
>My turn to write a code with what I've learned (i.e. the book presents a problem and I'll write a code to solve it.)

I plan to go over such after finishing the course at http://www.sololearn.com/, i.e., to test what I've learned so far.
project euler seems interesting but looks too high-level for me (with little to no explanations found online, but I'll try it nonetheless)
>>
>>54273240
I'm not sure it's exactly what you want, but you should take a look at Python Cookbook 3rd Edition regardless. It's pretty nice.
>>
>>54273288
If I'm going the 2.7 route, should I go for the 2nd or 3rd edition? (2nd ed teaches 2.4)
>>
Can someone explain perl subroutines to me please ?
Or point me towards a good reference (I've been looking in "learning perl" and "programming perl", I don't get it at all ...

I haven't seen hashes yet.
>>
>>54273399
Why aren't you using 3? It should be a good read anyway if you know the differences between the two versions. Another good one (for 3) is the recent Fluent Python.

You should also probably take a look at codewars and pythonchallenge.com.
>>
Someone give me an easy and simple programming project that will take about an hour to finish and make me learn a lot
>>
>>54273754
RPN calculator
>>
>>54273760
what is RPN?
>>
following problem

I have a arraylist where I neither can acces the nodes nor can I modify the given class itself

task is to write a iterator.

heres my train of though to solve this task:

I'll create an index and try to get the element if it works: bueno, if it doesnt: throw exception

would you accept this as a valid solving scheme ?
>>
>>54273796
it's a stack-based calculator that calculates things in postfix notation instead of dealing with parentheses for order of operations.

if you read up on the shunting yard algorithm, you can also add an algebraic interpreter that converts algebraic expressions to RPN instead of attempting to parse it manually as algebra, which is much more difficult.
>>
File: demo.png (151 KB, 328x274) Image search: [Google]
demo.png
151 KB, 328x274
I'm writing a very simple 2d pixel game engine. It is a C++ application with embedded V8 JavaScript engine and SDL2. All application specific code is to be written in JavaScript.

Actually it's not only for games, it can be used to write any GUI programs. You could write an image editor or a text editor with it.
>>
>>54273796
reverse polish notation

>>54274049
>C++ application
>game engine
>JAVASCRIPT
>>
took all day, but i finally entered the matrix
Dim mMatrix As Matrix = PresentationSource.FromVisual(Application.Current.MainWindow).CompositionTarget.TransformToDevice


tbf i procrastinated most of the day
>>
>>54274049
>2d pixel game engine
cool, this makes me interested to look into this, the pixel stuff too

but couldn't anyone write a text editor or an (simple) image editor with the gui stuff languages come equipped with already
>>
>>54274153
>Dim
>incredibly verbose line
>>
HELLO

ANY ADVICE FOR A JAVA SCRIPT KID?

What's some timewaste/fuckery that I should avoid while learning code? I feel like there's some casual filters in learning code, like common pitfalls people fall into.

I think a major one is being sloppy with formatting, and some people learn wrong for so many years.
>>
>>54274173
what do you mean by that?
>>
code how to post code? /code
>>
>>54274188
losing motivation

also

>JAVASCRIPT REEEEEEEE
>>
I wish composing programs had problems to solve, it'd be perfect.
>>
>>54273936
>instead of attempting to parse it manually as algebra, which is much more difficult.
Do you even recursive descent, son? You sound like an aspiring CS graduate.
>>
>>54274209
same way as spoilers but with code
>>
>>54274195
switch to a grown up language
>>
Need to find a better entity list.
>>
>>54274246
there's absolutely nothing wrong with using vb.net
>>
>>54274249
kek, couldn't you just track pixels changing and move accordingly?
>>
>>54274209
>>
I have lost all motivation to program after realizing how hard it is to make good real creative applications. What do you guys do when this happens?
Thread replies: 255
Thread images: 37

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.