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

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 321
Thread images: 33

File: ada.png (4MB, 4800x2700px) Image search: [Google]
ada.png
4MB, 4800x2700px
Previous Thread: >>55586885
>>
what were you programming when turkey died?
>>
>>55592646
Speaking of which, does anyone have questions about how to do things in Ada?
>>
>>55592782
I support the coup, but that's not programming related

>>55592818
OP here
Never used Ada in my life
Nobody has
>>
File: 1467398868589.jpg (475KB, 852x973px) Image search: [Google]
1467398868589.jpg
475KB, 852x973px
oh shit forgot to ask

What are you working on, /g/?
>>
File: 413e02LttjL._SY445_.jpg (18KB, 255x445px) Image search: [Google]
413e02LttjL._SY445_.jpg
18KB, 255x445px
>>55592837
spraying this on my mozzarella firefox
>>
File: Screenshot_20160716-001034.png (446KB, 1080x1920px) Image search: [Google]
Screenshot_20160716-001034.png
446KB, 1080x1920px
Working on a 4chan Android client for a CS exam
>>
First for Python
>>
I want to customize the CSS on Atom for a theme that looks like vim, but have no idea how to do anything... Any tips?
>>
Why is it that in these generals you guys only talk about hipster languages and in the real world I only see Java and C++?
>>
>>55592822
I do
>>
>>55593037
NEETs don't belong in the real world
>>
>>55593025
Just start doing shit with it until you get the hang of it, if you want something very specific just google it, CSS is pretty easy.
>>
Are there any good coding podcasts for newfriends?
>>
>>55593037

Because, we're all sick of the corporate backed bs?
>>
File: 1453329069688.png (494KB, 1242x1080px) Image search: [Google]
1453329069688.png
494KB, 1242x1080px
>>55593282
>le epic counterculture anonymoose h4x0r fuck the corporate system

Go back to the Mr. Robot thread fag.
>>
Anyone wanna give me some optimization advice?
working on pset5 for CS50, and i've finished it, it works, and is reasonably fast.
however, it could be faster. specifically, loading a trie from an alphabetized dictionary takes my code ~0.09s, while the staff's implementation is ~0.04s

Here are the relevant functions, which are the major slowdown of the program:
bool load(const char* dictionary)
{
root = mk_node();
FILE* fp = fopen(dictionary, "r");

if(fp == NULL){
printf("[!] Error: could not open dictionary %s\n", dictionary);
fclose(fp);
exit(1);
}

// iterate through the dictionary
int c;
node* current = root;
for(c = fgetc(fp); c != EOF; c = fgetc(fp)){

if(c != '\n' && c != '\''){
if(current->next[c-'a'] == NULL)
current->next[c - 'a'] = mk_node();
current = current->next[c-'a'];
}
else if(c == '\''){
if(current->next[26] == NULL)
current->next[26] = mk_node();
current = current->next[26];
}
else{
current->word = true;
dictionary_size++;
current = root;
}
}

fclose(fp);
return true;
}
>>
>>55593402
and this is the function to malloc and zero a new node:

node* mk_node(void){
int i;
node* n = (node*) malloc(sizeof(node));
if(n == NULL)
return n;
n->word = false;

for(i = 0; i < CHAR_COUNT; i++)
n->next[i] = NULL;

return n;
}
>>
My OffRailsfU tripcode is now defunct because reasons. I will be using another tripcode later on, and my secure tripcode in the mean time.
>>
>>55593436
Oh thank god your tripcode is safe we're all fucking looking forward to a /dpt/ full of tripcodes
>>
>>55593538

Sure thing, buddy.
>>
>>55593548
Whatever happened to that other guy, that was making a language called Pipes or whatever?
>>
What am I doing wrong with wpf data binding?
The image works if I set the content directly to the resource.
The converter is called, but the image is not updated.
It's a list view, the label that's also in the view is updated correctly to the bound model data.

App.xaml
<BitmapImage x:Key="WarningImage" UriSource="Resources/warning.png"/>


Mypage.xaml
<Image x:Name="image" HorizontalAlignment="Left" Height="18" Margin="10,10,0,0" VerticalAlignment="Top" Width="16" Source="{Binding Img}" />


MyPage.xaml.cs
public static readonly DependencyProperty ImgProperty =
DependencyProperty.Register("Img", typeof(ImageSource), typeof(MyPage), new UIPropertyMetadata(null));

public ImageSource Img
{
get { return (ImageSource)GetValue(ImgProperty); }
set { SetValue(ImgProperty, value); }
}


MainWindow.xaml
<local:MyPage Text="{Binding Info}" Img="{Binding State, Converter={StaticResource StateToImgConverter}}"/>


StringToImgConverter.cs
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var valueString = value as string;
if (valueString != null)
{
if (valueString == "a")
{

}
else if (valueString == "error")
{
return App.Current.Resources["WarningImage"];
}
}
return null;
}
>>
I have a Python question regarding the scopes of for-loops. Currently, I have two list of files (graph & stats) I need to loop through, which is passed through a function that extracts data from the files, and then the data is passed into another function for further processing.

    for i in graph_files:
xm, ym, = get_graph_data(i)
for j in stat_files:
sr, sm = get_stats_data(j)
plot(xm, ym, sr, sm)


This gives me an undefined error. I tried defining them first (xm, ym, sr, sm = None), but that seems to be throwing a bunch of None's into the plot() method.

What do?
>>
>>55593565
I remember having problems because didn't setted the Build action to Resource. IDK why you aren't declaring a FrameworkPropertyMetadata and passing it as the last parameter of the Register method.
Anyway, which resources/books are you using to learn WPF?
>>
>>55593565
>xaml
>>
>>55593282
yeah fuck that shit. that's why i use rust and go
>>
>>55593415
why don't you use
 memset 
instead of
 for(i = 0; i < CHAR_COUNT; i++)
n->next[i] = NULL;

?
>>
>>55593617
post the actual error here, like the log
>>
>>55593992

Yeah, I've been using mainly Rust. Go isn't really useful or interesting at all for me (Don't do much network / web server code where Go really has it's strength.)

That being said I still use a lot of C++. It's the language I've done most of my work in.

I cannot stand java at all.
>>
>>55593999
i didn't think of it while writing it, but good idea.
saves about ~0.02s

I also started reading one word at a time, rather than using fgetc().
could continue down that road and read larger and larger chunks, but it would require more refactoring.
>>
>>55593415
>>55593999
Why don't you just use calloc?
>>
>>55593999
>>55594100
>not portable
>>
>>55594106
post the portable version then Mr.portable
>>
>>55593560

I honestly don't remember. It used to be that memelangs were all the rage here.
>>
>>55594106
Yes it is.
>>
How shit is my code for brute-forcing a word puzzle?

from collections import defaultdict


def load_words(path):
with open(path) as infile:
return [line for line in map(str.strip, infile) if line.isalpha]

def valid_full_word(word):
return len(word) == 10 and word[0] == 'd' and word[-1] == 'n'

def main():
words = load_words('enable1.txt')
words = list(filter(lambda s: len(s) > 1 and len(s) <= 10, words))
print('loaded {} words'.format(len(words)))

d_list = []
n_dict = defaultdict(list)
for word in words:
if word[0] == 'd':
d_list.append(word)
if word[-1] == 'n':
n_dict[len(word)].append(word)

d_count = len(d_list)
n_count = sum(map(len, n_dict.values()))
possible_combinations = d_count * n_count
print('{} d-words and {} n-words'.format(d_count, n_count))
print('{:,} possible combinations'.format(possible_combinations))

if 'disarm' in d_list:
print('disarm found at {}'.format(d_list.index('disarm')))
if 'open' in [item for sublist in n_dict.values() for item in sublist]:
print('open found')
input()

full_words = [word for word in words if valid_full_word(word)]
print('{} full words'.format(len(full_words)))
for word in full_words:
print(word)

pairs = []
for word in d_list:
size = 10 - len(word)
for suffix in n_dict[size]:
pairs.append((word, suffix))
print('{} pairs'.format(len(pairs)))

with open('output.txt', 'w') as outfile:
print('===== FULL WORDS =====', file=outfile)
for word in full_words:
print(word, file=outfile)
print('===== DUAL WORDS =====', file=outfile)
for pair in pairs:
print('{}|{}'.format(*pair), file=outfile)

if __name__ == '__main__':
main()
>>
>>55594055
i was joking. the idea being that those languages (while not as widely used in a corporate setting) are still the babies of corporate giants (you could make a case for mozilla but eh come on). realistically the most effective languages with mature compilers are largely gonna be ones in which multibillion dollar companies have a vested interest. what can you do. i use C++ and sometimes C# which is a shitload better than Java
>>
I've been programming in C++, almost always in the terminal/XCode... How would I go about creating graphics for my code? I know how to use Processing, but it's not nearly as versatile as I'd like it to be...

Any tips?
>>
>>55594157
print '\n'.join(word for word in full_words)
>>
>>55594167

Meh, it's just definite definitions of corporate (Made vs Widely used by). I'm just trying to say all the "meme" languages in dpt are from devs being sick of a strict regiment of Java, C, and C++.
>>
>>55594213
what kind of graphics?

OpenGL is what you're looking for
>>
Why are there no NEET C# programmers?
>>
>>55594215
>python2
Fair point, the code block was a remnant from when it did more.
>>
>>55594229
that's... optimistic. could be a factor but i think it might have more to do with that most of the people in /dpt/ are hobbyists. not like NEETs are getting tired of the language they use in their day job
>>
>>55594260
because C# makes you employable. can't have that now can we?
>>
>>55594157
You should either put the filter stuff in load_words, or else make it a generator. You are created two lists for no reason.

Use 1 < len(s) <= 10.

d_list = [word for word in words if word[0] == 'd']

if 'open' in itertools.chain(word_list for word_list in n_list.values())

full_words = filter(valid_fill_word, words)

pairs = [(word, suffix) for word in d_list for suffix in n_dict[10 - len(word)]]

I was focusing on syntax, but more importantly 1) your main function is too large, and 2) it's difficult to see what you are trying to do. Use more comments and functions.
>>
>>55594233
Thanks! Any books/resources on learning to use OpenGL?
>>
>>55594332
This is a good resource: http://learnopengl.com/
>>
>tfw can't focus on programming because coup
>>
>>55594371
Are you in Turkey?
>>
>>55594382
No, but it's too exciting to watch unfold
>>
>>55594394
>coup
there will be no coup, though
>>
>>55594121
why?
>>55594130
you're clueless
>>
>>55594363
I'm being sonichu levels of retarded here, but if I already have XCode, where do I download OpenGL?
>>
>>55594433
lol fuck off

you can't just say
>hurr durr it's not portable
without posting the portable version , or proving why it isn't

kys
>>
>>55594434
see here on the right side of the page

https://developer.apple.com/opengl/
>>
>>55594464
Getting a weird error when I click the "Learn More" button

{"responseId":"11f2edff-996d-4904-9b7f-277bebde290b","resultCode":1003,"resultString":"request.uri.notfound","userString":"Invalid request, Service mapping to the requested URL is not available. ","creationTimestamp":"2016-07-16T00:53:27Z","userLocale":"en_US","requestUrl":"https://developer.apple.com:443/downloads/index.action?q=graphics","httpCode":200,"suppressed":[]} 
>>
>>55594601
well i don't a apple computer, but when i click on that it throws:
>Your session has expired. Please log in.
>>
>>55594601
see
https://forums.developer.apple.com/thread/51851
>>
>>55594631
>https://forums.developer.apple.com/thread/51851
Thanks! Gonna download the 7.2 Graphics Library in pic related
>>
>>55592837
Nothing because I don't have any ideas on anything that wouldn't look dumb on a github profile.
>>
>>55594916
>Nothing because I don't have any ideas on anything that wouldn't look dumb on a github profile.
You should program what YOU want, not what others MIGHT think of as cool or uncool.
>>
>>55594916
Write a compiler for your own programming language
>>
>>55594960
while YOU program SHE fucks CHAD without condom
>>
>>55594999
That's TRUE whether YOU program or NOT
>>
>>55594999
Who is SHE? Who is CHAD?
>>
why do I suck at programming?
>>
>>55594960
True, but I would like to get a job someday and I don't have a github yet, so I need to get started with stuff people would like.
>>
>>55595021
SHE is the girl who once laughed at your joke. CHAD is the tall, attractive man who you dislike for reasons you cannot articulate.
>>
>>55592818
I figured out how to do fizzbuzz in Ada
procedure Main is
procedure Fizz_Buzz;
pragma Import (C, Fizz_Buzz, "fizz");

begin
Fizz_Buzz;
end Main;
>>
>>55595021
She is that cute asian girl in your CS program you never got the balls to ask out. He is the guy that went for the PHD but still managed to look cool.
>>
>>55595053
Chad here

All you guys have to do is pretend to be a confident male and fake it until you get good at it then you will get all the women
>>
>>55595053 >>55595069
I don't know any of these people
>>
File: 0715162157a.jpg (825KB, 2560x1440px) Image search: [Google]
0715162157a.jpg
825KB, 2560x1440px
This should work. What is wrong?

Also, what were the very first original programs you wrote?
>>
>>55595158
Forgot to mention the compiler hangs
>>
>>55595164
>Forgot to mention the compiler hangs
>scanf("%d",&a);

are you retarded?

its waiting for your input you dip shit

just put a random number
>>
>>55595189
KEK
>>
>>55595189
Thank you, I just realized this, I scrapped a slightly larger "program" from this error, bear with me, I'm just learning C
>>
>>55595056
(You)
:^)
>>
How shit is this.

cd "C:\Program Files\LiveStreamer"
powershell -Command "Invoke-WebRequest "http://livestreamer-builds.s3.amazonaws.com/livestreamer-latest-win32.zip -OutFile live.zip"
powershell -Command "Invoke-WebRequest "https://rtmpdump.mplayerhq.hu/download/rtmpdump-2.3-windows.zip -OutFile rtmpdump.zip"
PowerShell Remove-Item -Path 'C:\Program Files\LiveStreamer\*' -exclude live.zip,rtmpdump.zip,LVUP.cmd -force -recurse
"C:\Program Files\7-Zip\7z.exe" x live.zip -aoa
cd "C:\Program Files\LiveStreamer\liveStreamer*"
xcopy * "C:\Program Files\LiveStreamer\" /E
cd "C:\Program Files\LiveStreamer"
"C:\Program Files\7-Zip\7z.exe" x rtmpdump.zip -aoa
cd "C:\Program Files\LiveStreamer\rtmpdump*"
xcopy * "C:\Program Files\LiveStreamer\" /E
cd "C:\Program Files\LiveStreamer"
del live.zip rtmpdump.zip
for /d %%x in (liveStreamer-v*) do rd /s /q "%%x"
>>
File: 0715162214a.jpg (1008KB, 2560x1440px) Image search: [Google]
0715162214a.jpg
1008KB, 2560x1440px
What did I do now?

>scanf("%d",&a);

returns "Hello, %d" as pic related
>>
>>55595288
Nigga are you Linux without any kind of graphical environment?
>>
File: 0715162216.jpg (1MB, 2560x1440px) Image search: [Google]
0715162216.jpg
1MB, 2560x1440px
>>55595300
Am I?
>>
>>55595288
This is the best shitposting so far
>>
>>55595288
its not %d , its %s

%s its for strings

%d its for numbers
>>
File: Sif.gif (35KB, 230x200px) Image search: [Google]
Sif.gif
35KB, 230x200px
>>55595311
You aren't
>>
>>55595317
Not shitposting, just new

>>55595329
Thank you
>>
Apart from programming languages, what are software design things one should know?
What of the software engineering, software architecture (what's even the difference between these two?) is a meme and what is useful?
Any good books?
>>
>>55595352
Just learn for loops, switch statements and if statements. Along with variables, if you are creative, you can solve literally any problem.
>>
File: 0715162224.jpg (1MB, 2560x1440px) Image search: [Google]
0715162224.jpg
1MB, 2560x1440px
>>55595338
>>
File: 1386214247466.jpg (65KB, 714x682px) Image search: [Google]
1386214247466.jpg
65KB, 714x682px
What's the point in getters and setters if your function isn't threadsafe regardless?
>>
>>55595311
>Pentium 3
You're still using that thing? I had got a 733MHz Celeron at this time, slow as fuck by todays standards, even with a lightweight Linux distribution.
>>
>>55595391
make them private
>>
>>55595408
Yeah but why would I do that if the function isn't threadsafe and I need to access the variable from outside the function?

All it does is add a shitload more clutter to the code for no reason.
>>
>>55595417
add semaphores and thread locks then

couldn't care less
>>
>>55595384
Look up X my friend
>>
>>55595427
why
would
I
do
that
if
the
function
is
not
threadsafe
though
>>
>>55595433
i
don't
give
a
single
fuck
let
me
sleep
already
>>
>>55594450
>I'm too dumb
ok
>>
>>55595384
install wine and run nature still suxx
>>
>>55595440
How is some anon on 4chan keeping you up
get your life together anon
>>
>>55595445
>I'm too dumb
>What's the point in getters and setters if your function isn't threadsafe regardless?
>you're dumb not me!111!!111! xDDDD
>>
File: 0715162231.jpg (671KB, 2560x1440px) Image search: [Google]
0715162231.jpg
671KB, 2560x1440px
>>55595392
>>55595431

Just my laptop for comfy bed use

>>55595446
Wine is not comfy desu senpai

What was the first useful/complex program you ever made?
>>
>>55595473
An IRC server.
>>
File: 0715162234.jpg (618KB, 2560x1440px) Image search: [Google]
0715162234.jpg
618KB, 2560x1440px
>>55595473
woops
>>
>>55595473
how's Australia?
>>
>>55595473
>What was the first useful/complex program you ever made?
- print even numbers from 1 to 100
- fizzbuzz
- etc
>>
>>55595417

Perhaps you should make your function thread safe?
>>
>>55595498
Why bother making a function threadsafe if that part of the program isn't threaded?
>>
>>55595498
wow, thanks. it works now
>>
>>55595503
Knock knock.

Race condition.

Who's there?
>>
>>55595524
Not here, because this part of the function is not threaded
>>
File: 0715162240.jpg (1MB, 2560x1440px) Image search: [Google]
0715162240.jpg
1MB, 2560x1440px
compiler expected identifier

Where did I fuck up?
>>
>>55595538
Figure it out yourself
>>
>>55595508

Thread safe programming should be the default. Until we hit quantum computers threading will probably become even more prevalent in the future.
>>
>>55595538
int main()?
>>
>>55595538
I love this kind of shitposting. Others don't even try anymore.
>>
>>55595538
when working with strings you don't need the address , &,

so you should do
scanf("%s", a);
>>
>>55595538
>Where did I fuck up?
Expecting help on /g/
>>
>>55595538
return 0;?
>>
>>55595554
int main(kampf)
>>
>>55595538
WITH INTS YOU USE %d YOU FUCKING FAGGOT
>>
>>55595538

10 / 10 your troll attracted much posting.
>>
>>55595561
>>55595543
>>55595569

I learned basic C yesterday. Give me a chance

>>55595567
>>55595571
>>55595554
thank you
>>
>>55595575
return jews;
>>
>>55595603
#include <stdio.h>

int shoah(long long int jews)
{
return 0;
}

int main(int argc, char *argv[])
{
printf("%d\n", shoah(60000000000000));

return 0;
}


We'll just pretend that didn't happen.
>>
>>55595588
>I learned basic C yesterday
I'm a week in K&R. Have fun.
>>
Do floppy disks have any use besides vintage computers? Or is there something unique I can do with software on them
>>
File: Floppy-Main.jpg (44KB, 500x333px) Image search: [Google]
Floppy-Main.jpg
44KB, 500x333px
>>55595646
>>
Right now I'm making a programming language to compile to assembly for low level stuff. I'm still going through alot of planning but right now I'm missing two key components. I need a name for the language and a logo. Any suggestions?
>>
File: Floppydisk2-640x480.jpg (84KB, 640x480px) Image search: [Google]
Floppydisk2-640x480.jpg
84KB, 640x480px
>>55595646
~
>>
>>55595646
Still used in missile bases apparently
>>
>>55595567
>scanf on unbounded string
That's literally on the same level as gets. Use fgets.
In fact, don't use scanf ever. It's a terrible function.

>>55595538
>%s for int
>return:0;
>>
File: 0715162257a.jpg (880KB, 2560x1440px)
0715162257a.jpg
880KB, 2560x1440px
>>55595659
>>55595680

for programming
>>
File: FA9N61CF54HJ6GG.MEDIUM.jpg (37KB, 620x465px) Image search: [Google]
FA9N61CF54HJ6GG.MEDIUM.jpg
37KB, 620x465px
>>55595699
>>
>>55595495
not to be a dick but what is useful about fizzbuzz
>>
>>55595862
~10% of programming interviews will ask you about it so may as well know it.

Also general basic programming shit so why not.
>>
>>55595158
Are you using an int for a name?
You should be using a char array.
>>
File: nosql.jpg (26KB, 732x491px) Image search: [Google]
nosql.jpg
26KB, 732x491px
hey someone help me with my homework (but seriously I could use advice)

Making an iOS app with Firebase, but I'm still trying to work out how to structure the nosql database.

Just as an example, say there's users and each user can create as many posts as they want.

So is it better to store this as:
users/posts/postkey1, postkey2 etc.
posts/postkey1 (and so on)/post details etc.

or store the posts according to the user who created it:
posts/userid/post1, post2

see pic
>>
>>55595035
Because you haven't had enough experience

https://www.youtube.com/watch?v=R2_Mn-qRKjA
>>
>>55596043
nevermind I just realised the second method is shit
>>
>>55595495
import Control.Monad
main = mapM_ print [0,2..100]
>>
>>55595670
A more in depth description would help, assuming this is real and not a shitpost (and it probably is) call it G
>>
File: 1467653851419.gif (2MB, 750x750px) Image search: [Google]
1467653851419.gif
2MB, 750x750px
Anybody here speak iptables?
>>
How can I compose functions in C?
>>
http://pastebin.com/fjkBnDrH
http://pastebin.com/ZTY2wsEG
http://pastebin.com/yByTYRCu

These java functions from AutismCraft generate the noisemaps used to color biomes with more than one color assigned to them. I want to implement them into a certain world renderer, but the section I would need to add it to is written in C.

TL;DR How the FUCK would I go about reconstructing these in C?

Pic related, it's me.
>>
>>55592937
I finally gave into the botnet. Fuckit, at least I have a browser that works now
>>
>>55596314

As in to create them or to do the f(g(x)) shit?
>>
>>55596418
To create them.
>>
>>55596338
struct for Handler members, functions for all its methods

same for Generator.

functions in place of methods should take an additional input for a pointer to the struct that corresponds to an object
>>
>>55596440

Well, take the canonical main function as an example.

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


Return type (int) comes first, then function name (main), then arguments in parentheses.
>>
>>55596314
>>55596440
typedef void (*genfn_t)();

genfn_t compose(genfn_t a, genfn_t b)
{
static const unsigned char shellcode[] =
// movabs a, %rax
"\x48\xb8\x00\x00\x00\x00\x00\x00\x00\x00"
// callq *%rax
"\xff\xd0"
// movq %rax, %rdi
"\x48\x89\xc7"
// movabs b, %rax
"\x48\xb8\x00\x00\x00\x00\x00\x00\x00\x00"
// jmpq *%rax
"\xff\xe0";

long page_size = sysconf(_SC_PAGESIZE);

unsigned char *fn = aligned_alloc(page_size, page_size);
if (!fn)
return NULL;

memcpy(fn, shellcode, sizeof shellcode);
memcpy(fn + 2, &a, sizeof a);
memcpy(fn + 17, &b, sizeof b);

if (mprotect(fn, page_size, PROT_READ | PROT_EXEC) == -1) {
free(fn);
return NULL;
}

return (genfn_t)fn;
}

x86_64 Linux only.
>>
File: pragmatic.jpg (30KB, 500x631px)
pragmatic.jpg
30KB, 500x631px
Wooow... Pic related really drops in quality after the first few chapters...
>>
>>55596460
I want to take two function pointers and return a function pointer to the compressed functions.
>>
>>55596470
 P
NOT
R
T
A
B
L
E
>>
>>55596482
I know. I clearly stated as such.
Obviously anything to do with code generation isn't going to be portable.
>>
File: 1267388251489.jpg (8KB, 117x218px) Image search: [Google]
1267388251489.jpg
8KB, 117x218px
>>55596450
Holy fuck thank you. I was really close, the part of the picture I was missing was that last bit.
>>
>>55595694
>In fact, don't use scanf ever. It's a terrible function.
let the man make mistakes
or are you gonna tell him to use a """safe""" language instead
>>
>>55596499
I see. thanks but How can I do it without code generation?
>>
>>55596509
You can't.
Get over it.
>>
>>55596508
(f)scanf is shit because it's so fragile. If it fails, it leads the stream in an inconsistent, half-read state, and makes it very difficult to recover from.
fgets + some other parsing function (including sscanf) is much better and is what should be taught to beginners.
>>
>>55596474

>and return a function pointer to the compressed functions

Wait, do you intend to create a function on the fly that will compose these two functions? Because if so, you're going to be needing to do some system specific shit. C does not do "create new function at runtime." At least not in a way defined by the language.
>>
>>55592646
how do I assign a struct onto an array of chars/bytes?

char array[69];
struct some_struct thing;
(struct some_struct) array = thing;


this doesn't work, but it is my intention
>>
>>55596596
With a union.
union {
struct some_struct s;
char a[sizeof(struct some_struct)];
} pun = { .s = thing };

// Do thing with pun.a
>>
>>55596640
I always wondered what unions were good for

thnx
>>
>>55596558
>C can't compose functions
Really? That's a fundamental basic operation. Wew.
>>
>>55596748
>That's a fundamental basic operation
No it's not.
>>
>>55594100
>>55593999
Why don't you just use alloca?
>>
>>55596798
That has literally nothing to do with that problem.
>>
>>55596808
stack allocation is faster than heap allocation
copy everything out to the heap right before you blow out the stack
should be faster when amortized
>>
>>55592782
>implying Erdogan has not become a brutal tyrant that has been killing Turkey as a secular democratic state
>>
>>55596814
1: alloca is non-standard. VLAs is the portable way to dynamically allocate automatic memory
2: How the hell is doing it on the stack and then copying to heap memory supposed to be faster? You're incurring the malloc overhead either way. All you're doing is adding a bunch of unnecessary copying.
>blow out
I don't even know what you mean by this.
>>
>>55596857
you're clearly inexperienced
>>
>>55596865
You're clearly retarded.
>>
I improved my Rust quine:
fn main(){(|a|print!("{}({:?})}}",a,a))("fn main(){(|a|print!(\"{}({:?})}}\",a,a))")}
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345


That's 85 characters for Rust. Can anyone golf this? I bet functional languages have this in the bag.
>>
>>55596313
ufw is my interpreter
>>
>>55596920
Why do code blocks wrap earlier than plain text in posts?
>>
>>55596748

Not really. C is a system's language. It is designed to be able to be used in very minimal environments. Creating a new function at runtime means the following must happen:

1. Memory is acquired
2. Memory is given execution privileges
3. New assembly is generated in this buffer

Is this something you can reasonably expect done on a language designed for everything from microcontrollers to virtual machines to operating systems, web servers, and more? I think not.

Languages like Lisp can get away with this because they are intended to be dynamic in nature. Code is either outright interpreted or JIT compiled. This is NOT the case in C, where if you want anything JIT'd, you have to write it yourself from scratch, and you can have no assumption that it's going to work on every platform.

Welcome to systems programming. Leave all of your assumptions about what a language is or should be at the door.
>>
>>55596937
don't forget that you can create a scheme interpreter in C without too much struggle, if you really wanted one
>>
>>55596953

I've seen a scheme interpreter written using only around 4000~5000 lines of C. Of course, it was an ugly hack, and it's purely interpreted, but it's the most distributed scheme, so at least that's impressive.
>>
>>55592942
Post a link to an apk so i can try it out?
>>
Anyone have an efficient way to loop over a fuckhuge list in Python and break it down into smaller lists every n-th element, resulting in one huge list of lists?
>>
>>55597132
>efficient
>Python
BWAHAHAHAHAHAHAHA
>>
>>55597132
why would you take a terrible data structure and make it terrible^2 ?
>>
Now, here's a piece of C++ that causes undefined behavior. On x86-64 Linux, when compiled with GCC 5.4, if optimization flags are used, it works as expected. Otherwise, it will cause a segmentation fault.

#include <iostream>
#include <functional>

int square(int x)
{
return x * x;
}

int times_two(int x)
{
return x * 2;
}

template <class Func>
std::function<int(int)> compose(Func a, Func b)
{
auto newfunc = [&](auto c) {
return a(b(c));
};
return newfunc;
}

int main(void)
{
auto two_x_squared = compose(times_two, square);
auto twox_squared = compose(square, times_two);
int foo = two_x_squared(3);
int bar = twox_squared(3);

std::cout << foo << std::endl << bar << std::endl;
return 0;
}


Why does it work as expected with -O3? Well, C++ can do some aggressive inlining in some cases and basically create all of this lambda shit as static functions. These kinds of optimizations haven't been around since C++'s creation in 1985 though, which is why lambda capture is a relatively new thing. And given that this behaves differently depending on which optimization flags are used, it's still undefined behavior.
>>
>>55596302
Basically its an assembly language that targets multiple architectures. Im making it to help save time by automatically handling .rodata and .data sections, and instead of using real registers, im planning on using 'ghost registers' that are optimized during compilation for the architecture. The syntax is still pretty much like any assembly language accept with alot of influence from C.
>>
>>55597167
>Basically its an assembly language that targets multiple architectures.
so GNU Assembly?

the ghost registers sound cool though.
you'll probably find yourself compiling to the least common denominator though
>>
>>55597167

You know, what you just described sounds exactly like LLVM IR.
>>
>>55597120
Right now is not ready at all, it lacks 2/3 use case realization and some general polishing
>>
>>55597244
lmaoooooo
>>
>>55597244
Yeah, I looked into llvm briefly for previous projects, but I figured that compiling down to Assembly (>>55597187 yeah, sorry forgot to mention that, it doesnt compile straight to native and needs GNU as) would give me a few benefits for debugging aswell as make compatibility to call subroutines from existing C Libraries easier to implement

Oh yeah, another thing I plan is that it will be able to call C functions without any abstraction between the languages
>>
>>55597423

>able to call C functions without any abstraction between the languages
That's easy. Just don't mangle function names and don't throw exceptions.

Also, test.
>>
>>55595056
I don't get it.
>>
Okay, this is my new trip from now on... at least when I'm posting from my desktop. Some of the characters are... difficult to post from my phone. Which will admittedly probably make it last longer.
>>
when you read from a texture in opengl, then e.g. in a 2 texels wide texture the coordinate of the first texel is at 0.25 and the second texel is at 0.75

but how exactly do normalized device coordinates map to texture coordinates when rendering to a texture? to render to a 2 texels wide texture, do you make sure fragments are rasterized at -0.5 and 0.5 in normalized device coordinates?
>>
>>55597538 (Me)
ok jim blinn's corner - a trip down the graphics pipeline has a detailed explanation, seems like it will have the answer, this is why i prefer proper documentation and such, it takes longer to sift through but once you've done it you're like an expert on the subject and you get it just right without any sloppy mistakes that you otherwise might not even had been aware about
>>
>>55597524
It looks like it's just calling a C function to do fizzbuzz.
>>
File: 1454453520982.jpg (332KB, 1177x1019px) Image search: [Google]
1454453520982.jpg
332KB, 1177x1019px
>>55592646
I want to implement a lexical analyzer and parser in C, but I don't know how.
I figured I'd start with the symbol table, should I be using a BST for that?
Anybody have info, or examples?
>>
>>55595311
>testing
Why not unstable, are you a bitch?

Do it this way
#include <stdio.h>

int main(int argc, char **argv)
{
if (argc < 2)
return 1;

printf("Hello %s\n", argv[1])
}


On linux you use arguments unless you're doing something with ncurses, it's just the law.
In actual projects use argp.
>>
>>55593722
stackoverflow/msdn
no books
>>
public class StubFactoryFactoryProxyImpl extends StubFactoryFactoryDynamicBase
{
public PresentationManager.StubFactory makeDynamicStubFactory(
PresentationManager pm, PresentationManager.ClassData classData,
ClassLoader classLoader )
{
return new StubFactoryProxyImpl( classData, classLoader ) ;
}
}
>>
>>55598273
why is it that whenever i see java code it looks like disgusting shit like this
>>
>>55598337
it's not even proper java, it has the disgusting C# style braces
>>
>>55593992
I agree, I only support Go, it's a counterculture language developed exclusively by anti-corporate counterculturalists such as myself
>>
>>55598273
ENTERPRISE QUALITY
>>
>>55598364
Get fucked you sad twat, don't talk shit about C#
>>
>>55598476
>java is shit
>C# isn't shit
k tard
>>
>>55598515
C# is literally the best language out there.
It's not as fast as C or C++, but it's fast enough for 90% of applications.
It doesn't give you a way to explicitly lay out objects in memory, but that's the only real drawback.

Otherwise it's a fucking joy.
>>
>>55597162
you're capturing the pointer by reference which go out of scope when compose returns, ofc it doesn't work
use capture by value (duh)
>>
>>55598553
stay delusional, microsoft sucks at programming and programming language design
>>
>>55598577
What other language has same IDE support, debugging support, and almost instant compile times, while still having tons of useful language features.

You almost NEVER feel like it's a hassle programming in C#.

They're even ref returns in C# which elevates some of the problems I've had with the language.
>>
>>55598553
2 Rupees have been deposited into your Microsoft® account.
>>
>>55598620
They're even adding ref returns in C# 7**
>>
>>55598631
ad hominem
>>
>>55598577
>F#
>nulls
noooo
>>
>>55598553
Generators / yield are a great feature, super useful. I really want them added to C++ and Rust, hand-coded iterators come up all the time in systems programming.
>>
>>55598701
>>
>>55598701
>I got told
>>
>>55598916
>>55598918
ad hominem
>>
>>55593436
No one fucking cares, dumb tripfag.
>>
Is it bad programming to include processor definitions.
>_CRT_SECURE_NO_WARNINGS
In particular
>>
Why can't I have a const float in C++?

Why does it have to be constexpr?
>>
>>55599475
static const float i mean
>>
>>55599485
But you can, Anon.
>>
File: XFqRmi7.jpg (78KB, 640x1136px) Image search: [Google]
XFqRmi7.jpg
78KB, 640x1136px
>>55594916
>not being shameless

it's like you want to never do anything in your life lmao
>>
>>55599485
it's just const float in C++
>>
>>55599475
Because floats are shit so the standard only allows const integral values
>>
>>55599692

C++ allows for const float. The only time constexpr is required for anything is when dealing with other constexpr shit. Obviously things like template parameters and the like need to know their values at compile time, so you can't stick a random static const value in there.
>>
Deferred shading is a fucking lie.
All it does is do the exact same fucking job of the fragment shader in forward rendering and early Z culling.
I fail to see how this is AT ALL more efficient if not LESS efficient than forward rendering.
>>
>>55599721
>I fail to see how calculating only lights that affect screen space is more efficient than calculating every light that's near the player
>>
I'm implementing Levin search.
>>
>>55599733
deferred lighting != deferred shading
>>
What should I program next?
>>
>>55599762
AIXI
>>
>>55599733
Fucking idiot, fragments that are off screen don't fucking get put through the fragment shader.
Forward rendering DOES only calculate lights that affect screenspace.
>>
>>55599861
you can still get overdraw with forward rendering
>>
File: LaughingElfMan.jpg (16KB, 255x352px) Image search: [Google]
LaughingElfMan.jpg
16KB, 255x352px
>>55595069
>cute asian girl
>cs program
uhhh
>>
>>55599906
Not much, not enough to warrant the deferred shading meme.
>>
ありがと
>>
>>55600093
谢谢
>>
>>55600017
it can be useful if you're vertex limited and you have a lot of lights, but otherwise it's mostly a meme
>>
File: .webm (2MB, 720x404px) Image search: [Google]
.webm
2MB, 720x404px
>>55595646
>>
python

matrix =[list('abc'),list('pqr'),list('zxy')]

How do I extract

a,q,y
c, q, z

And what is that kind of procedure called?

I know of the term transposing - what is this, and how is it done?
>>
>>55598559
that's not the reason you dumb shit
>>
>>55599242
>include
in the source file? yes
in the build script? no
>>
>>55600593
you should really study some linear algebra
https://en.wikipedia.org/wiki/Matrix_(mathematics)
>>
>>55600693
k
>>
>>55593565
Found a hack fix, it works if you set the image.Source to the args.newValue in the UIPropertyMetaData propertyChangedCallback.
>>
>>55600593
>>> [v[i] for i, v in enumerate([list('abc'), list('pqr'), list('zxy')])]
['a', 'q', 'y']

>>> [v[-1-i] for i, v in enumerate([list('abc'), list('pqr'), list('zxy')])]
['c', 'q', 'z']
>>
>>55600593
take every row len+1?
>>
>>55600593
for i in range (0, len(matrix)):
print matrix[i][i]
for i in range(0, len(matrix)):
print matrix[i][len(matrix)-1 - i]
>>
I disassembled a windows executable and found the following code in the main function.
0x0065f0ca    b9d6f06600   mov ecx, 0x66f0d6
0x0065f0cf 894c2404 mov [esp+0x4], ecx
0x0065f0d3 59 pop ecx
0x0065f0d4 eb1b jmp loc.0065f0f1
0x0065f0d6 50 push eax
0x0065f0d7 b82df06600 mov eax, 0x66f02d

As you can see there is an unconditional jump with some more instructions right after it. In this function there were no other jumps to these instructions, so the will never get executed. Why would a compiler add them to the executable?
>>
>>55600593
matrix =[list('aqy'),list('cqz')]
>>
I’m also a man of science. Of numbers. The way I move through space with minimum waste and maximum joy is all about mathematical probabilities. I look at things happening around me and try to extrapolate what they will be like in the future. I seek patterns in the numbers, and what I see ain’t pretty.
>>
>>55601220
i cringed when reading that as well
>>
>>55601111

No DCE
>>
>>55601220
I myself am more of a mage. I play with numbers and symbols like an artist. They are like different colors and brushes, all interacting and interwoven in perfect harmony within my painting. The world is my canvas, on which I realize my art using math and numbers.
>>
To program or to get women

What do you choose and why?
>>
>>55601453
easy, programming
i don't even like women anyways
>>
>>55601453
combine
>>
>>55601485
Hold up you be sayin we program a woman? I like where this is going
>>
>>55601453
>implying programmers don't already get all the women
>>
>>55601623
name one time programming has got you laid
>>
>>55601453
program because the underachieving normie lifestyle is not for me and i can't stand most people, if i were to have a gf/wife it'd be at a later point in my life and i'd still be doing programming or whatever i'm interested in and/or makes money like running some business and investing
>>
>delete comment
>code breaks
>>
>>55601647
Carmack, is that you?
>>
>>55601729
in some sense you could probably say i'm the next carmack
>>
>>55601736
what sense?
>>
>>55592646

I have a python program that reads a PNG image.

When I take the data from the PNG image after it has been processed and compress it again, it gives a result that is the same as the original data block except for the beginning and end. It appears the original image has a bit of extra shit added. What is this extra shit?
>>
Still looking for inspiration on the next rust project. Thought about doing a small game and I'm just not feeling it at this point.

Kinda wondering if there is a decent detours / windows driver api library ported over to rust. A simple trainer / memory scanner would be interesting.
>>
>>55601696
my bet goes to character encoding, make sure the whole line commented out doesn't contain some invisible character incompatible with the expected file encoding
>>
>>55601743
>smart af
>maxed out all math stuff in high school effortlessly
>didn't go to college, programming/cs is all self-taught
>doing graphics programming and coming up with clever algorithms on my own
>obsess about latency
>invented my own low-latency input processing algorithm
>probably gonna do VR stuff in the future
>>
>come back
>hiroshima made the code blocks font shit
ffs
>>
>>55601858
If you are so smart and good at programming how come you haven't made an application that has made lots of money yet? Checkmate
>>
>>55601888
i'm making it
>>
>>55601858
Only a dumb person would call himself smart.
>>
>>55601858
difference is that carmack had results to show for AND got the wife and kids

he literally has everything
>>
Working on my X11 screen saver and locker written in Rust.

Published a first release few days ago, been using it for a week replacing xscreensaver.

Implemented system suspension support yesterday, realized CLOCK_MONOTONIC stops running while the system is suspended, so hooked up to the logind DBus signals for suspension to correct the timers with the system time and added a couple commands to do the same with acpid or whatever else.

Now going through the code base to add comments to things that might be unclear or fixing edge cases I didn't consider.

Then I'm going to add support for xscreensaver hacks, and the new screensaver overlord will be born.
>>
>>55601888

Why are you so indoctrinated into the financial system? You realize that fiat currency is creating a big bubble that will burst right? If your currency isn't physical gold / silver you don't truly have anything.
>>
>>55601906
i'm literally smart and countless people have spontaneously said i'm incredibly smart
>>
>>55601911
>got the wife and kids

implying that's an accomplishment
>>
>>55601911
he's also decades older than me, shit takes time bruh, and i'm not trying to say i'm as good as or as better than him, just entertaining anon's thought when he compared me to carmack
>>
>>55601926
I've been called smart when I installed Win 10 on my family laptop.
>>
>>55601917

Fully compatible with what you're replacing?

What advantage does this replacement written in rust provide? Why should users change over?
>>
>>55601929
ritchie, thompson, and most others didn't manage
>>
>>55601953
lucky them
>>
>>55601858
cringeworthy desu
>>
>>55601965
unlikely, ritchie died alone
>>
>>55601904
What are you making lets hear it Mr. Bill Gates

>>55601923
Because money rules everything. To attain physical gold and silver you need LOTS OF MONEYYY
>>
>>55601938
carmack started id software at age 21 my man
>>
>>55601988
>come up with a tech idea you know will be huge, it clicks right away
>spend over half a year working hard as fuck alone to get it where I want to be because I'm not a technical retard with another tinder or flappy bird idea
>finally coming together and fucking mind blowing to everyone I show it to, multiple competitions won. big companies interested
>competitors are also MUCH more expensive and have no where near the same flexibility, and not even commercially out yet. I take a huge shit on them as a one man project.
>>
>>55602006
wouldn't happen if he never got to meet romero desu
>>
>>55602006
anyone can register a company, so have i, still takes time to develop software and make it big
>>
hey guys, do any of you guys in the professional world really need to use a debugger? due to a health condition, i can't use a debugger and i was wondering if this would hinder me if i wanted to look toward programming as my career
>>
>>55602044
no

>due to a health condition, i can't use a debugger
nigga what
>>
File: ktomdmr.png (652KB, 539x473px) Image search: [Google]
ktomdmr.png
652KB, 539x473px
>>55601953

That's because dmr & co. were nerds then, but would be ironically hip and attractive by today's standards.

They were before their time.
>>
>>55601988

Gold: $1,337 per oz,
Silver: $20.22 per oz

As the fiat currency crashes in the future both of them are going to jack sky high in value. If you're living cheaply and can afford gold it's the better route. If you're broke like the majority of people across the world that aren't in the top 10% silver should be a decent alternative.

>>55602030
It's more than time to get good income developing a software business. You gotta get enough traction and funding to not die a early death.
>>
>>55602082
i'm releasing it within 3-6 months and funding is no problem, i appreciate your concern though
>>
>>55601951
The compatibility will only be with the hacks compiled for xscreensaver, which is, just the savers.

My implementation has a slighlty different design, where ALL of the rendering is done in another process, this includes the optional rendering of a dialog box, which reduces the attack surface even further.

This also allows fancier effects when starting/stopping the screen saver, for instance the saver I use does a progressive blur instead of the only option xscreensaver has, which is fade in and fade out.

On top of that the creation of screen savers in other languages is much simpler because there's a simple JSON based RPC between the daemon and the process doing the fancy graphics, while in xscreensaver you either do them in C/C++ or you're pretty much fucked because there's a lot of additional code to have compiled in that comes from xscreensaver.

Also I just wanted to make fancy screen savers in Rust and it was more of a hassle to try and make Rust generate what xscreensaver wanted than making it from scratch.
>>
>want to learn Lisp because always hear it's the greatest languages etc
>google 'learn lisp'
>the faggot niggers tutorial is first hit on google

There's gotta be something better than Zed "Cunthead" Shaw's tutorial, right?
>>
>>55602204
>JSON
kys
>>
>>55602234
The messages are small and sent sparingly, which means I don't need any kind of serialization/deserialization performance or correctness, and every language out there has a library to handle JSON.

Give me a better choice with these loose requirements.
>>
>>55602224
https://www.gnu.org/software/emacs/manual/eintr.html
>>
>>55597338
Oh. You should make a thread once it's ready, it looks fucking beautiful and I'd love to try it out!
>>
>>55602224
http://www.gigamonkeys.com/book/
>>
>>55602224
SICP
>>
>>55602272
>>55602287
thanks fellas, I read a bit further on that site and it looks as if they're not even affiliated with Cunthead anyway. I just got triggered with the learnxthehardway crap I guess.
I have 3 different tutorials now so I'll look into them all.
>>
>>55601453
Program an AI waifu.
>>
>>55602224

ftp://ftp.micronet-rostov.ru/linux-support/books/programming/Lisp%20-%20Scheme/[No%20Strach]%20-%20Learn%20to%20Program%20in%20Lisp,%20One%20Game%20at%20a%20Time%20-%20[Barski].pdf

It's aimed at beginners
>>
>>55601951
>What advantage does this replacement written in rust provide? Why should users change over?
These are questions that stump every Rust fanboy, because there's literally no reason to do this ever. They like to think they're accomplishing something but they're basically just copying someone else's efforts and changing the syntax so the type comes after the variable instead of before.
>>
>>55602332
I explained the reasoning, I'm not rewriting it in Rust just because, I'm not rewriting it at all, the architecture is different.

I'm making a replacement with the requirements I personally had, if others find it useful then good for them, otherwise I couldn't care less, I made it because I want to use it.
>>
>>55602303
>I just got triggered with the learnxthehardway crap I guess.
you poor baby
>>
New thread: >>55602377
>>
>>55602332

Rust is perfectly fine for developing new programs that do things differently or take advantage of it's concurrency support / features.

It's just when people recreate already widely used software I have to ask what they intend to implement that the old version doesn't and what specifically would make people want to use the new version. I mean outside of practice reinventing wheels that offer no advantage or niche feature over older wheels is wasted effort.
>>
>>55602385
Ignore this thread, do not post in it unless saging
We'll wait till a janny deletes it
>>
>>55602354
You described changes to the program design that you could have implemented in C/C++ without flying off the handle and rewriting the entire thing. It's called "submitting a patch," anon. You might have heard of this idea.
>>
>>55602435
Did you check the source code for xscreensaver? Or ever communicated with jwz?

No? Then come back when you did.

Also it's about optimizing time, it takes less for me to rewrite something as small as xscreensaver with feature parity and an architecture I prefer than trying to change a 25 years old filled with code that hasn't been compiled in I don't even know how many decades.
>>
What would be the best language to write a graph database in? I was thinking it would work well with any OO language, but I dunno if there would be a perk to using a functional language.
>>
Actual new thread

>>55602501

(project 2501 edition)
>>
any good /g/ approved books that can teach me c++ or pyhton
Thread posts: 321
Thread images: 33


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

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.