[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 - Santiago Gonzales edition
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: 30
File: op.jpg (229 KB, 1920x1080) Image search: [Google]
op.jpg
229 KB, 1920x1080
previous thread: >>53912129

What are you working on, /g/? Are you a feminist too? Who is your ideal role model and why is it me?
>>
>>53917964
I've browsed this board for years and I have yet to see a single line of code posted here.
>>
>>53918070
Here, as in this thread?

Literally look through the last thread. Plenty of code.
>>
>>53918070
 Console.WriteLine("fuck off m8"); 
>>
>>53918070
if dream in code:
print "you're a prodigy programmer for realz"
>>
>>53918095
>using
Console.

>not adding
using static System.Console;
and just doing
WriteLine("ayylmao");
>>
>>53918268
>polluting the global namespace just because you're too lazy to type "con" and let IntelliSense complete
>>
>>53917964
ylyl belongs to >>>/b/
>>
>>53918299
How about you pollute this with your mouth?

*unzips dick*
>>
File: Untitled.png (2 MB, 1680x1050) Image search: [Google]
Untitled.png
2 MB, 1680x1050
I'm working on finding all the /dpt/ threads. we can never have too many.
>>
>>53918323
lol epic xd
>>
>>53918268
Csharts everyone
>>
>>53918338
one day, i hope /g/ can be 100% dpt threads, even for just a moment.
>>
>>53919165

We could have something equivalent to that if we had our own programming board. Although then, threads like /dpt/, /wdg/, and /fpg/ might just sort of all meld together and form a bunch of smaller threads that are less general. However, we'd also lose a lot of users, because we don't have the constant inflow of traffic from complete retards. you may think this is a good thing, but if you think that's the case, go look at the /tech/ board on firetires' site. Their "daily programming thread" is more of a weekly/monthly thing. It currently has 85 posts, and was started on April 1st. By comparison, we go through a few DPTs every day.
>>
>>53917964
who is this guy in the photo?

A construction worker?
>>
>>53917964
any man who calls himself a feminist should be castrated. i would rather have a gay son than a feminist son.
>>
>>53920279
he's only pretending because he doesn't know any better
>>
>>53920279
This desu. Takes a certain level of toughness to take a dick in the arse.

Takes a certain level of faggotry to allow women to walk all over you.
>>
>>
>write a naive implementation of strcasestr
>test it against glibc strstr

I thought it would be a huge bottleneck, but it's only 0.1s slower!
My tripcode generator now manages 28ktrips/s on one core!
>>
>>53920279
>>53922351
you faggots need to get with the times. every girl wants to hear you believe in feminism now. the secret is there is no standard definition of feminism, so you can define it how you like and then not even adhere to it.

I say, "I'm a feminist in that I believe God created all of mankind equal, however I believe it is a man's responsibility to watch over and protect his woman and be her guide towards Heaven."

All of which I believe.
>>
write a program that reverses arrays
you can't use the any of the code posted before yours. Ill start:
#include <iostream>
#include <cstdio>

int main()
{
int Arr[] = { 1, 2, 3, 4, 5 };
int n = sizeof(Arr) / sizeof(Arr[0]);
int temp, i, j;

for (i = 0, j = n - 1; i<n / 2; i++, j--)
{
temp = Arr[i];
Arr[i] = Arr[j];
Arr[j] = temp;
}

std::cout << "\nReverse array" << std::endl;

for (i = 0; i<n; i++)
std::cout << Arr[i] << " ";

getchar();
return 0;
}
>>
>thread full of shitposts

new thread >>53922429
>>
>>53922397
I also tested it against my old regex-based search and it's 4ktrips/s faster than before!
>>
>>53922459
This is bait, but I will bite anyway.

What women really want is a man to protect them, love them, and treat them as equal.

Feminism is not equality.
>>
>>53922459
there are girls that aren't brainless sheep

feminism is really cancerous
>>
Let's all make a C++ program as a collective
Everyone gets to write one line of code and in the end I will compile it. If it works Ill stick a sharpie up my dogs pooper

#include <iostream>
>>
>>53922526
while (1) malloc(1); /* leak all the memeory */


:3
>>
>>53922526
main() { cout << "i'm a faget"; }
>>
>>53922526
#include <boost/algorithm/algorithm.hpp>
>>
>>53922498
>What women really want is a man to protect them, love them, and treat them as equal.
I mean, isn't that pretty much exactly what I wrote?

>>53922503
>brainless sheep
what?
>>
>>53922542
not in int main, you already fucking failed
>>
>>53922565
fucking retard
>>
>>53922565
No, you are saying that women want to use a man to further themselves.
>>
>>53922559
>>53922559
You two are shitty
>>
>>53917964
Android question - how would I achieve the following:
user draws with a finger, I need to grab vectors/points that are an approximation of a drawn lane. even better if said approximation can be controlled - resulting in better / worse resemblance of the input.
I'm using libgdx if that's of any help
>>
>>53922590
It's not about want. It's about being a man, a leader. Dominion over your kingdom and sharing the fruits of your labor with those you love.

Just my two cents on how to go about the whole feminism thing. Outright denial will not work for long.
>>
cshart is for fags
>>
>>53922638
I agree with the first line fully.

However, Feminism is about female supremacy.
>>
>>53922526
#include <iostream>
int main()
{
int* wat =(int*) 0x99999999;
std::cout << *wat << std::endl;
>>
feminism is for fags and even pretending to be a feminist makes you a fag
>>
>>53922476
#include <iostream>
#include <array>
#include <algorithm>
#include <iterator>

int main() {
std::array<int> arr = { 1, 2, 3, 4, 5 };
std::reverse(arr.begin(), arr.end());
std::ostream_iterator<int> iter (std::cout, ", ")
std::copy(arr.begin(), arr.end(), iter);
return 0;
}
>>
File: dumb bitch BTFO.png (307 KB, 492x449) Image search: [Google]
dumb bitch BTFO.png
307 KB, 492x449
>>
>>53922661
maybe some women feel that way. and I would agree that you would be a fool to let those women control you.

you can see feminism, the equal rights of women, differently is all I'm really trying to get at.
>>
/dpt/ - debating penis-craving tramps
>>
>>53922701
But you can advocate for equal rights for women without being feminist. I do, and I am not.

Feminism is very much supremacist, go and look at it on the internet.
>>
>>53922526
using namespace std;
>>
>>53922747
>go and look at it on the internet.
no thanks. I want to a fairly liberal school and heard all the viewpoints. My mind is made up on the matter. mankind is only supreme as a whole on Earth.
>>
>>53922798
>baiting this badly

I will bite. Just because you learn something is true in school doesn't make it true.
>>
>>53922701
"Equal rights of women" is an oxymoron, no?

Equal rights for all women, but not all people, apparently.
>>
File: tegaki.png (49 KB, 400x400) Image search: [Google]
tegaki.png
49 KB, 400x400
>>53922765
 public static void main(String[] args) {
>>
>>53922798
>liberal
>all view points

RETARD LEVELS CRITICAL
>>
>>53922821
>I'm not baiting but bored and stating my beliefs.

clearly. I'm saying I was taught feminism in its various forms in several courses and made up my own opinions about it. Don't let extremists tell you what feminism is, just because they say something doesn't mean it's true either.
>>
File: tumblr_nxkq7k2TPC1stfw62o1_500.jpg (54 KB, 500x493) Image search: [Google]
tumblr_nxkq7k2TPC1stfw62o1_500.jpg
54 KB, 500x493
Just came out of an interview. Got the job, effectively a pay raise from 20 to 28$ an hour

Fuck yeah, thanks bros. Reading this thread every day helped a shit ton
>>
Java is the best programming language
>>
>>53922885
how lol
>>
>>53922877
>No true scotsman

I'll bet ISIS aren't muslim as well.


The truth is that feminism has turned many countries into shitholes. Look at sweden for instance.
>>
>>53922885
>$28/hour job
Wow, being a code monkey truly does suck. I make that as an intern at a engineering corporation that deals with government contracts.
>>
>>53922933
That's not true you are just a sexist piece of poo
>>
Who's using Scala, and what do you make of it?
>>
>>53922976
It's shit Java is still superior
>>
>>53922924
The nonstop shilling for functional programming, because the place is a functional programming shop.

Thanks, g shills

(I'm a no degree fag BTW)
>>
File: haskell-ready-for-industry.png (1022 KB, 1000x3000) Image search: [Google]
haskell-ready-for-industry.png
1022 KB, 1000x3000
Functional programming is taking over. /fpg/ is here for all your fp discussions!

>>53922963
>>
>>53923013

I'm absolutely not using Haskell.
>>
>>53922933
>this will be my last /pol/ post on /dpt/ for the day:

you are correct, ISIS aren't muslim on the whole. muslim means one who submit's to God. ISIS worship scripture and their prophet, their idolatry will be their demise but I obviously can't tell when that will occur.

Sweden became a shithole when they decided it was a good idea to give half their income to the government. We are clearly running on the same path which is frightening.

Fight supremacy in all its forms: be it white, black, jew, male, female, christian or muslim. Love God, your wife, your family and your friends and learn everything you can in the time you're given.

I'm going back to work.
>>
>>53923056
>ISIS
>Islamic State Of Iraq and Syria
>Not Muslim

Sure, they follow the hadiths a lot more strongly than some islamic sects, but that doesn't change that they aren't muslim.

Sweden became shit from migrants and socialism. Aside from that I agree.
>>
>>53923098
No it hasn't diversity strengthens every country. It is great for the economy you bigot
>>
>>53923050
>I'm absolutely not using Haskell.

Why? Too hard?
>>
>>53923122
But it strengthens patriarchy fuckface, most of the migrants are MEN
>>
>>53923013
>all this butthurt
>>
io.write("Lua master race. So simple, so clean.")
>>
>>53923147
>ruby isn't his meme language of choice
>>
>>53923122
>great for the economy
You know that's because it adds to the population of poor unskilled works in the economy, who are willing to work for less and with less benefits. Of course that doesn't apply to Sweden with it's socialist wealth redistribution programs, it just puts more strain on the system by adding more people who can't put in as much as they take out.

They are literally doing it for shits and giggles and probably-more-than-quasi-religious political beliefs.
>>
how can I tell python to load an entire instagram profile? Right now my scraper pulls off of what's immediately on the page, but I need to get all the pictures.
>>
>>53923147
It really is a very well designed language. There is maybe two things I don't like about it. Every other language in the world is more along the lines of dozens of things I don't like (or straight up hate) about it.
>>
>>53923238
Agree. It's pretty much the only scripting language I can write that I don't hate myself afterwards.
>>
>>53923130

No. It's useless.
C++ is "too hard", but at least you get a performance gain for the trouble.

As for functional programming generally, it's fun. But Haskell is a pointless way to learn FP.
>>
>>53923327
lel C++ isn't too hard. I'm sure haskell isn't too hard after you get used to get. git gud
>>
>>53923147

JavaScript in mustache and glasses.
>>
>>53922798
>I want to a fairly liberal school and heard all the viewpoints
my sides are in orbit
>>
>>53923349

You haven't done much cross platform C++ have you? Or linked a large library or application. Even after getting used to it, it's always hard. But just writing the stuff id not too bad.
>>
>>53923397

I know he's lampooning the idea, but there are generally people who believe that. They think they are worldly because they've been indoctrinated by the breadth of liberal progressive "ideas"
>>
>>53923005
fuck you
>>
>>53923441

s/generally/genuinely/g
>>
Newfig here, Trying to figure out how linked lists work in C. I made a program that just allows me to dynamically create and remove nodes from a list.

However, I was wondering if anybody had a cleaner way of printing out the list than what I did, which is velly ugry.
puts( "Setting searcher to root of list." );
searcher = root;
printf( "This is node number %d.\n",searcher->x );
if (searcher->next == 0) {
puts( "Reached end of list.\n" );
break;
}
else searcher = searcher->next;
while (1) {
printf( "This is node number %d.\n",searcher->x );
if (searcher->next != 0)
searcher = searcher->next;
else break;
}
puts( "Reached end of list.\n" );
>>
>>53922948
I'm only making $17/hour at an engineering contractor for the govt :( I'm also a first-year with low experience so lol
>>
>>53923496
>
while (1) {
//blah blah blah
if (searcher->next != 0)
searcher = searcher->next;
else break;
}


Why?
>>
>>53923522
>only making $17/hour
>only
bruh be grateful
>>
>>53923496
turn this >>53923531 into this:
while (searcher->next) {
searcher = searcher->next;
}
>>
>>53923544
I am senpai :')
>>
Tempted to learn Rust, but what should I make
>>
>>53923496
for (struct list *ptr = head; ptr->next; ptr = ptr->next) {
//...
}
>>
>>53923622
>; ptr->next;
Whoops, I mean ; ptr;
>>
>>53923522
I guess you have to find the right one. As soon as I graduate they will probably ask me back on salary at $55,000. Engineering is so good.

>>53923622
>struct outside of typedef
Wew lad.
>>
>>53923227
Use iconosquare or something

Surely that would be easier
>>
how do I develop mobile apps using only C++.
>>
>>53923664
I don't want to work in defense so I'll probably only intern with them this summer and go somewhere else later. Who knows :)
>>
>>53923678
Depends on platform. On android you can use the native framework. Not too sure about iPhone
>>
Not coding but scripting. I'm writing a generic install script for a teamspeak server.

Not worrying about the files atm, just the sysad tasks.

#!/bin/bash

TSHOME=/usr/bin/teamspeak

if [ ! -d "$DIRECTORY" ]; then
mkdir $TSHOME
fi

groupadd -r teamspeak

adduser teamspeak -d $TSHOME -c 'Teamspeak Service User' -g teamspeak -n

chown teamspeak:teamspeak $TSHOME
chmod 700 $TSHOME


The idea being I dump the launch script and binaries in $TSHOME, ran as the teamspeak user.

Any advice? Is /usr/bin the right place to put the ts server? Should I use a system account? Are the permissions appropriate? How would I jail such a server?
>>
>>53923678

You shouldn't. You should use Java for Android, and whatever ghey language Apple's pushing for iOS, but if you absolutely have to use C++, I'm pretty sure QT will compile for most mobile platform targets.
>>
>>53922476
#/usr/bin/env ruby
arr = %w[use a non-shit language for once /g/]

puts arr.reverse
>>
>>53923733
>I'm pretty sure QT will compile for most mobile platform targets.
yeah if you buy a licence wew
>>
Do you think he would look cute if he crossed dressed?
>implying he doesn't
>>
>>53923751

Unless you opensource your code, in which case, it's free to use. But it is a frustrating business model.
>>
>>53922476
reverse
>>
>>53923774
I thought all the mobile stuff was locked away under the licence?
>>
>>53923411
Yeah, but that's only a small part of using the language. Anyways, I agree with you on the usefulness of Haskell. You can do the exact same shit in another language and you don't need to learn the edgy programming style.
>>
Working on IPAM integration with OpenLDAP, bind9 and ISC DHCP
>>
I've read a book on C++ and have learned up to things like the STL, namespaces, templates, preprocessor, exception handling, and all OOP things. Where do I go now?

Same thing with Python, I just don't have any project of mine or a way to put my skills into use, how do I move on?

bonus question: how important is programming for theoretical CS?
>>
Lads, I have a stupid problem: I think I am retarded. When it comes to programming no matter what I do I just can't understand it and get it to stick. I have tried multiple times to get it, stick with it, and learn it but I legitimately cannot. I've tried codecademy, books, etc and still I can't get it.

I want to learn programming though since it's quite literally the future, but I just feel so retarded when I try.
>>
>>53923833
Set out to write something that is personally useful to yourself.
>>
>>53923833
sounds like software development isn't for you. try something else.
>>
>>53923678
shiggy diddly. for games it's ok since you don't use the typical GUI stuff much
>>
>>53923813
I can literally NEVER get OpenLDAP to work. The DNS configuration just never comes through no matter what guides I use.

I can create and configure my own BIND DNS no problem, but when I tell OpenLDAP to use it all hell breaks loose and no client can auth. Any tips?
>>
>>53923833
try different languages until you find one that clicks. I could never get into C++ or object oriented shit for the longest time. various flavors of BASIC worked for me.
>>
>>53923825
For C++, familiarize yourself with C++11 and C++14 features. Things like move semantics, Standard Library Templates and Algorithms, lambda functions, metaprogramming, concurrency, etc.

Read Fluent Python. I can't help you with coming up with a project.
>>
>>53922476
from random import shuffle
def reverse_arr(arr):
while True:
mixed = shuffle(arr)
if mixed == arr[::-1]:
return mixed
>>
>>53923873
>I can't help you with coming up with a project.
I understand, I just can't see ow this is everything there is to C++ etc. Can I take up any project now and have no problems coding it?
>>
File: image.jpg (175 KB, 1280x720) Image search: [Google]
image.jpg
175 KB, 1280x720
>>53922922
No it's not.
Python is godtier!
>>
There is literally nothing wrong with being a Liberal I vote Liberal all the time
>>
>>53922922
i'm shilling for ruby because it makes me feel like a hipster
>>
I need to learn how to implement some sorting algorithms and data structures like linked list for school. Do I need knowledge like this for the real world? Isn't it retarded to learn easily googleable things like that? Most of those are built in modern languages anyway...
>>
>>53923890
Starting a serious project will expose the gaps in your knowledge. You'll almost certainly have problems coding it, but it seems like you have a good base going for you so you should be able to surmount those difficulties.
>>
>>53923890
you will never complete a project where you had no problems. it will simply never happen.
>>
>>53923013
Dumb frogposter
>>
>when your program randomly crashes from a fatal error
>tfw looking in tens of thousands of lines of code to find the problem
>>
>>53923937
desu lad if you're not interested in sorting algorithms programing isnt for you
>>
>>53923937
Linked lists in particular, not really. Data structures in general: yes, definitely. 1) Even if they are built in to your language's standard library, you need to have an understanding of what the strengths and limitations of those data structures are; 2) sometimes the default data structures are not enough, and you need to create a new one or tailor an existing one to fit your needs.
>>
>>53923855
I can give you some config files if you want.
It wasn't all that hard.

sudo apt-get install slapd ldap-utils bind9 bind9utils bind9-dyndb-ldap
sudo dpkg-reconfigure slapd


Save http://pastebin.com/yE5pJp8D to `/etc/ldap/schemas/bind-dyndb.schema`

And then import it with `ldapadd -Q -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/bind-dyndb.ldif`
You can then make your zones with e.g. Apache Directory Studio.
I'm building my own front end for it though.

You should create an organizational unit for the DNS tree under your domain.

Then finally, append to `/etc/bind/named.conf.local`:

dynamic-db "ldap" {
library "ldap.so";
arg "uri ldap://localhost";
arg "base ou=DNS,dc=example,dc=com";
arg "auth_method simple";
arg "bind_dn cn=admin,dc=example,dc=com";
arg "password XXXXXX";
};


Just replace it with the proper DNs and password, and you should be good to go.

You have to create some idnsZone objects under the DNS OU, with all the SOA record parameters.
Under those zones, you can add the idnsRecords. Make sure to use idnsName as the RDN in both cases.
>>
>tfw spent 4 hours tracking a memory corruption bug
Somebody shoot me. Jesus Christ I need a drink.
>>
>>53924040
did you find it?
>>
>>53923882
shuffle modifies it's argument, it doesn't return a shuffled sequence. Pls learn how to bogosort.
>>
>>53924000
Are you retard or something cause that's not how you debug, and that's not how you should be developing
>>
what knowledge do i need to have to make a web crawler?
>>
>>53918323
Your dick has a zip?
>>
>>53924040
R U S T
U
S
T
>>
>>53924074

A knowledge of the web and crawling.
>>
>>53924069
>retard
idk maybe. I could never get into using a debugger. it just doesn't jive with me. I prefer to make a change, like inserting a msgbox, and recompiling and running it again until the problem's solved. compiling only takes like 3 seconds.
>>
>>53924098
>this is what Pajeets actually think
>>
Why aren't you using strfry() for all your C applications?
>>
>>53924015
Top lad. God be with yee.
>>
>>53924074
graph traversal
>>
>>53924054
Yeah.
It was like 8 functions deep and it was basically
memcpy(data, buf, sizeof(buf));

The entire function that memcpy was in was a horrible mess and I'm going to rewrite it, and whoever wrote it assumed that data would be greater than or equal to the size of buf.
It would do horrible things like cause the stack pointer to point to garbage.

>>53924081
I tried it a long time ago and thought it was pretty nice. I'd like to see where it goes.
>>
>>53923581
You should join the team that's making a microkernel in Rust and rewriting all of GNU in Rust.
>>
my algorithm analysis professor is so shit at teaching. he spends 90% of classtime working through mathematic proofs which we aren't tested on or even expected to learn, and then he spends 2 seconds briefly skimming over the actual concepts. not to mention while he's working through the mathematical proofs or writing a bunch of equations to deal with algorithms he doesn't even say what the variables stand for half the time
https://www.youtube.com/watch?v=OQ5jsbhAv_M
learned more about dynamic programming in the first 16 minutes of this one video than i did in 4 of his 50 minute classes
>>
>>53924074
An internet connection
>>
>>53924197
holy shit are you me?
[spoiler]are you taking about logan/amini?[/spoiler]
>>
>>53924236
nop idk them
>>
Tips for implementing a million, trillion, thousand opcodes in C?
http://imrannazar.com/Gameboy-Z80-Opcode-Map
>>
Hey guys in java I'm trying to create a mini console game.

I created a method and want to make a while loop that attacks every 2 seconds.

I'm looking for a class that i can import that keeps track of time. Anyone know of one?
>>
>>53924294

megaswitch
>>
>>53924294
Use a table of function pointers anon
>>
>>53924294
Looks like there's a lot less than a million, trillion, thousand.
>>
>>53924105
idk what a "Pajeet" is, but my method of debugging has worked fine for over 10 years.
>>
>>53924294
Lookup table of function pointers?
>>
File: definition.png (23 KB, 642x335) Image search: [Google]
definition.png
23 KB, 642x335
>>53920279
>>53922503
>>53922661
>>53922747
>>53922933
>le "evil" feminists are why im a virgin
>reeeeeeeeee
Fuck off. >>>/pol/
>>
>>53924373
Switch is the best. It's the fastest, even compared to a LUT.
>>
anyone know a good way to go about learning lua for someone who's already decent with C?
>>
>>53924421
Programming in Lua 2nd edition. Learn the API too. Lua is pretty nice as a library.
>>
Is JCreator good?
>>
>>53923218
>it just puts more strain on the system by adding more people who can't put in as much as they take out.
http://www.ft.com/cms/s/c49043a8-6447-11e4-b219-00144feabdc0,Authorised=false.html?_i_location=http%3A%2F%2Fwww.ft.com%2Fcms%2Fs%2F0%2Fc49043a8-6447-11e4-b219-00144feabdc0.html%3Fsiteedition%3Duk&siteedition=uk&_i_referer=#axzz3Ti4Rfx9e
>>
>>53924388
>>53924397
That's what I've done so far, more or less. What do you think: is it better to map at a 1:1 ratio, or should I write more general functions?
>>53924390
Close.
>>
>>53924399
When did that ever come up?

Ad hominem much
>>
>>53924490
Some sand leaked from someone's vagina. There is a need in her heart to make everyone notice.
>>
File: feminist tattoo roastie pride.jpg (33 KB, 450x584) Image search: [Google]
feminist tattoo roastie pride.jpg
33 KB, 450x584
>>53924399
>roasties getting toasty
>>
>>53924472

What kind of megaweed are you smoking? Just use intellij or egglips.
>>
>>53924520
How about Netbeans?
>>
>>53924555

Yes, netbeans is fine. It's also got the best UI editor of the bunch.
>>
>>53924489
I would probably run some tests first to check whether using function pointers is slower than a giant switch

indirect calls aren't the fastest
>>
>>53924489
There is a limited number of ops, then rest is operands, no? Just use some bit masking and a lookup table of function pointers.

>>53924482
Nice job linking a walled journal site. From the title I can tell that they do, in fact, pay taxes, but not that they use less than or equal to what they put in. Also, great job spending an hour looking for evidence in your favor that you paid fucking money for. You definitely aren't a religious nut.
>>
>>53924573
Ok I'll try those.
Thank you, anon.
>>
>>53924597
>run some tests first to check whether using function pointers is slower than a giant switch
You are joking right?
>>
>>53923729
>not coding but scripting
what

there's programming
which includes scripting

and coding
which includes programming and markup
>>
I have been programming in C for four years now, and I have never used function pointers and unions outside of when I was learning.

Explain to me why I should.
>>
private int Attack(){
int autoAttack = random.nextInt((11 - 17) + 1) + 20;
return autoAttack;
}


I'm trying to set my method to activate every 2 seconds. What are some options on doing this?
>>
>>53924688
>>>>>"coding"
men program
>>
>>53924698
unions -> variants
function pointers -> higher-level functions, polymorphism, and callbacks
>>
>>53924698
>Not using function pointers to implement state machines
>>
>>53924698
what have you made? lol

also
there are almost always multiple ways to solve a problem, so I'm sure you can always do something without X language feature if you're less comfortable using so

in a small interpreter project I did a while ago, I used function pointers for the built-ins and I used a union for the variables

etc

you only "should" use a language feature when it's actually the best method, both for you and the program

:)
>>
>>53924698
I use function pointers for callback functions, and unions with unnamed structs for easy iterating.
Like,
typedef struct {
union {
struct {
uint8_t foo;
uint8_t bar[10];
uint8_t baz;
uint8_t qux;
};
uint8_t elements[13];
};
} __attribute__((packed)) struct_t_t_t;
>>
>>53924721
>unions -> variants
You forgot type-punning.
>>
and they tried to say gaymen isn't /g/ related https://www.youtube.com/watch?v=1X21HQphy6I
>>
>>53924739
Tons of things. Never written an interpreter, sounds fun

>>53924751
interesting
>>53924721
I understand that I can use function pointers to make structures act like objects. However, why wouldn't I use java in that case?

>>53924725
Never needed to implement a state machine
>>
>>53924785
But state machines are magic, anon.
If you ever do anything with parsing, state machines and pushdown automatons are essential.
>>
>>53924760
Yeah, they are good at that, but I can't seem to get them to work with constexprs. Compiler complains that I'm accessing an uninitialized member when the other is initialized. Which is dumb, seeing as it is a fucking union.

>>53924785
>Using another language for a particular feature
Then use that language? no one is tying you to C.
>>
int multiple(int a, int b) returns the product of a and b

implement this function without using the same implementation as has been posted previously in this thread. i'll start

 return a*b; 
>>
>>53924785
>However, why wouldn't I use java in that case?

Maybe you hate virtual machines?
>>
>>53924098
compleyely fucking retarded
>>
>>53924490
Did you not see all of the cringeworthy posts earlier?
>>53924511
>projecting this hard
>>53924600
>Nice job linking a walled journal site. From the title I can tell that they do, in fact, pay taxes, but not that they use less than or equal to what they put in.
>but not that they use less than or equal to what they put in
Did you not read the "pay £20bn more in taxes than they receive" part? I understand it's a shock that not everything you read on /pol/ is true, but you're going to have to cope.
>>
>>53924823
return b*a;
>>
>>53924888
I wrote the last three
>>53924836
Good point, c++
>>53924808
Its been a while since I have looked at them.
>>
>>53924098
HOW have you never gotten into debuggers? It beats writing print statements by a long shot.
>>
>>53924888
>Did you not read the "pay £20bn more in taxes than they receive" part?
>walled site
>only see top of article name
>pay us money to receive lies
No I didn't.
Also did you know I pay a hell of a lot more in taxes then I receive? Well shit, how can that be? After all I am a rich white guy.

> I understand it's a shock that not everything you read on /pol/ is true, but you're going to have to cope.
Most of it is shit. But that doesn't make 'the opposite' true.
>>
Writing more hardwares

module vsync_count(clk,reset_n,ven,count,vsyncout_n);    //once hsync has happened 768 times, trigger vsync
input clk,reset_n,ven;
output vsyncout_n;
output [9:0] count;

reg [9:0] count;
reg vsyncout_n;

always@(posedge clk)begin
if(reset_n==1'b0)begin
count<=10'd0;
end
else if(ven==1'b1 && count==10'd805)
count<=10'd0;
else if(ven==1'b1)
count<=count+1'b1;
end

always@(count)begin
if(count<10'd6)
vsyncout_n=1'b0;
else
vsyncout_n=1'b1;
end

endmodule
>>
>>53924951
idk, maybe because I'm a hobbyist with no formal training. I'm sure a debugger is an invaluable tool, but I usually like solving the problem myself. (except for the fatal errors that cause a random crash; I hate that shit, but it doesn't happen often, so no real need for a debugger)
>>
>>53924964
>walled site
Whether the site is walled or not has no relation to the validity of the information.
>pay us money to receive lies
Ah, the "facts that contradict my narrative can't be true" fallacy. How does it feel to not even be aware that you're essentially a living test monkey for the study of confirmation bias in humans?
>>
>>53922459
>every girl wants to hear you believe in feminism now.
cue articles from sexually frustrated feminists saying they won't date feminist numales anymore

too bad most men with self-esteem don't want to date bitchy slut... sorry, I mean empowered sexually liberated womyn

next thing she knows, she's 35, the wall, bla-bla-bla
>>
>>53925038
When you're using an IDE, it's almost synonymous with building and running a program. When a program crashes (at least in Xcode), it immediately switches to debugger mode and you can see the exact stack frame where it crashed. SUPER convenient when working with a big program. It's just convenience, nothing else.
>>
>>53922885
congrats man! keep at it
>>
I'm retarded. Why doesn't my MIPS program work? It's supposed to get the sum of every number divisible by 3 and 5 to number N.

.data

Sum: .word 0
N: .word 10

.text
.main:

daddi r3,r0,3
daddi r5,r0,5
daddi r1, r0,1
daddi r6, r0, 0
lw r10, N(r0)

loop:
beq r10,r1,end

ddiv r2, r1, r3
dmul r2 ,r2 ,r3
beq r2, r1, fizzbuzz

ddiv r4, r1, r5
dmul r4, r4, r5
beq r4, r1, fizzbuzz

daddi r1, r1, 1

j loop

fizzbuzz:
dadd r6, r1, r6
daddi r1,r1, 1

j loop

end:
sw r6, Sum(r0)
halt


Current test gives me 23.
>>
>>53925119
well the ide I use doesn't auto switch to debugging like that. I've tried using the debugger but it's usually a step-through process and just feels slow and tedious. I have use trace statements to solve problems before but it's been awhile.
>>
>>53925226
is it because you are trying to run it on x86?
>>
>>53924992
module vsync_count(clk,reset_n,ven,count,vsyncout_n);    //once hsync has happened 768 times, trigger vsync
input clk,reset_n,ven;
output vsyncout_n;
output [9:0] count;

reg [9:0] count;
reg vsyncout_n;

Why? Just put the declarations together.
module vsync_count(
input wire clk,
input wire reset_n,
input wire ven,
output reg [9:0] count,
output reg vsyncout_n
);

Stop repeating yourself. Also remember to
`default_nettype none
you prehistoric motherfucker.

>>53925075
>Whether the site is walled or not has no relation to the validity of the information.
Yes it does. I can't verify you aren't bullshitting me. Or that their statement is bullshit that ignores certain variables to prove a point. I'll call that a lie of omission, you can call it scripture. How funny you mention confirmation bias.

You of course didn't attempt to contradict my other point. Wealth redistribution is never true redistribution, there is overhead. Of course we pay more than we get out. The fact that framing this in regards to refugees in particular points to a bias in the publisher. Just look at the overhead of government in Europe. It's a hell of a lot more than 20 billion quid.

Refugees or just poor whites, it doesn't matter, poor people put in less than they take out, overhead accounted. That's obvious. And refugees are mostly poor as fuck. It's an obvious calculation. Defending the poor refugees against the obviousness of their situation is acceptance of insanity. The only possible argument any progressive can make is that the additional cost is worth it in the long run, yet none of them do so, because doing so would be near impossible.
>>
File: 4L_r27gpnDO.jpg (47 KB, 500x500) Image search: [Google]
4L_r27gpnDO.jpg
47 KB, 500x500
>>53922459
My definition of feminism is that women are sex objects and they should not be allowed to work or go to school. They should look pretty, only speak when spoken to, cook, clean, and make and raise babies.

We radical feminists now bros!
>>
>>53925239

I'm trying to run it in the winmips64 simulator so I think it should be ok.
>>
>>53925226
>ddiv r2, r1, r3
>dmul r2 ,r2 ,r3
I'm sure there is a much better way to do modulo.
Also, while I'm no MIPS expert, isn't 'ddiv' only supposed to have 2 parameters, and the result stored in HI and LO?
>>
>>53925354

yeah would be better to cut out the ddiv and dmul as they're both very expensive but it'd be better if I could get the thing working first.

ddiv r1,r2,r3 takes the value in r2, divides it by r3 and stores the result in r1.
>>
>>53925392
>ddiv r1,r2,r3 takes the value in r2, divides it by r3 and stores the result in r1.
Yeah I know, but I was looking at a MIPS reference and there was only two arguments. You should get the modulo free from the division, and you can just test if it's zero to see if it's a multiple.
>>
>>53925283
My final version is better spaced and commented but I didn't want to post it because it has my name and Uni all over it.

I like to keep my outputs and regs separate, that's just how I was taught.
>>
i don't mean to shit up the board but i just wanted to thank you guys for helping me out so much. i'm a loser who doesn't really get encouragement irl. whether it be you guys answering my stupid questions or just browsing the threads you guys are always positive and i just wanted to say thanks!
>>
File: (3).png (60 KB, 981x695) Image search: [Google]
(3).png
60 KB, 981x695
>3 WEEKS LEFT OF UNI
>still need to add comments to my entire dissertation project
>today my supervisor told me i need to write at least 10-15 more pages of the dissertation
>i have 3 other courseworks due at the same time for 3 other classes

NOT GUNNA MAKE IT.
>>
>>53925283
To add: I will admit there is another option. That poor people actually do put in more than they get out, and so everyone does, but even more. In that case: holy shit, socialism makes everyone equal by making everyone equally poor. Fuck that.
>>
>>53925441
Anonymous, you've ruined the entire thread! Dammit!
>>
>>53925432
>I like to keep my outputs and regs separate, that's just how I was taught.
That's fine. But seriously,
`default_nettype none
will save your ass. And to make that work you'll need to declare the outputs as wires and have assigns from the regs to the output wires, which gets messy. that's why I do it.
>>
File: metal edge.jpg (147 KB, 1280x1040) Image search: [Google]
metal edge.jpg
147 KB, 1280x1040
>>53925448
all i've got... all i've got is insane...
>>
>>53925407

AFAIK the modulo get discarded, hence the roundabout procedure. Also I was trying to find a bug in a program that doesn't have bugs. I was expecting the answer to be '3+5=8' but in actuality the answer was '3+5+6+9=23'. I'm going to bed once I get this to write the answer back to terminal.
>>
>>53925484
How would it save my ass? I'm not doubting you, I'm just curious.
>>
I'm trying to develop a simple C program that does an interview with a N number of users and ask each one 4 questions and at the end of it I need the progam to show: who's the oldest of them, the percentage of single man compared to the total, the average age of the ones who smoke and the sex of the youngest widow.

 #include <stdio.h>

int (main) {
int X, i, Age, highestA, lowestA, mens, singlemens, smokers, smksAsum;
char sex, MS, smokesYN, youngestwidow; // MS = marital status
float percSingleM, averagesmkA;
i=0;
highestA=-1;
singlemens=0;
smksAsum=0;
smokers=0;
highestA=121;
do while (X>=10 || X<=30);
printf("Type a number between ten and thirty")
scanf(%d, &X);
do while (Age>=0 || Age<=120);
printf("Age between zero and a hundred twenty")
scanf(%d, &Age)
do while (sex=M || sex=F)
printf("Sex M or F");
scanf(%c, &sex);
do while (smokesYN=Y || smokesYN=N)
printf("Smoker Y or N");
scanf(%c, &smokesYN);


am I doing ok so far?
>>
>>53925348
>implying you'll ever be able to support a wife and family by yourself.
>>
>>53925567
The default type is wire. So if you mistype a variable name it will interpret it as a new variable of type wire instead of a syntax error. In synthesis it work optimize out the undriven wire and optimize out your entire design. Because you misspelled something. You might read the warnings and see that the synthesizer is optimizing out a bunch of regs, but it isn't easy to detect where you misspelled the variable. That's how it saves your ass.
>>
>>53925598
i'm not reading that. learn how to use brackets
>>
>>53925603
black people have 8-10 kids each while unemployed and don't have any issues so why would i have a problem raising 2-3 kids?
>>
>>53925598
>do while (X>=10 || X<=30);
Do what? Do fucking what?
>>
>>53925598
You're not even close.
>>
>>53925652
>black people have 8-10 kids each while unemployed

Only because they get gibsmedats from uncle sam.
>>
>>53925633
Everything here is inside an always block though. And by typing the output, regs twice I make sure everything is spelled correctly otherwise it will throw an "illegal reference to net".

I understand the need for redundancy in big confusing designs however. Maybe I just haven't done anything big enough to understand what you're trying to convey to me but I will take note of this.
>>
>>53925664
I typed N instead of X
X is supposed to be max number of interviewed people
I don't want it to show an error when somenoe types a number that is not inbetween 10 and 30
I want it to keep asking for stuff before proceeding into the next question if someone types something incorrectly that's why I used Do while
>>
>>53925724
>that's why I used Do while
It's not doing anything.
>>
>>53925724
maybe if you >>53925641 then you wouldn't make elementary mistakes like what you did
>>
>>53925724
do what?

DO WHAT???? DO FUCKING WHAT?

do while is written as such
do { i++; } while (i > j)


do is command that will be looped for as long as while is not true.
>>
>>53925722
If you are familiar with Python you'll know misspelling a variable will cause the code to not work, because it will interpret the misspelled variable as a new variable, Verilog will do the same thing. The preprocessor directive prevents that behavior.
>>
>>53925740
so should I use
   for(x <= 30; x>= 10) 

or
>>53925766

All I want is for the progam to print the questions scan the answers proceeding to the next question when the answer is a valid input
and I want the interview to repeat a X ammount of times.
>>
I'm working on a mod for TF2
>>
Is it a good idea to enclose JS functionality for a webpabe in its own object?
>>
>>53925820
why do you want a loop for that? use fucking if command, loop is for repeating something untill you achieve decired outcome.

>for(x <= 30; x>= 10)

don't ever talk to me or my wifes sons ever again.
>>
>>53925835
I play TF2. Say a little bit more about this mod.
>>
File: 1342054600704.jpg (71 KB, 300x562) Image search: [Google]
1342054600704.jpg
71 KB, 300x562
>>53925598
>Do you smoke or do you not smoke?
Yes?
>>
So I'm working with binary numbers, and I'm trying to get a binary adder/subtract to work. I get the concept of adding binary numbers, but when I try to put in code it gets too big. So I tried working with strings, but it's more confusing. Any tips on reading a user input in binary as a string, adding or subtracting 1 to it for starts. I'm messing with java, but c++ works okay too
>>
>>53925598


You should indent your program properly.
Basic C++ program.

int main() {
int u = 10; //Declare and assign on the same line if I'm just going to assign it straight after declaration anyway

For(int i = 0; i < u; i++) { //Every time we change scope(use curly brackets) we indentate
cout << "My dick is " << i <<" inches long. \n";
if(i < 6) // here I indentate even when I don't use brackets because the scope changes
cout << "Nigger.";
} //From my program the length of each scope is clear. I can see where all of my loops begin and end.

}



How your code LOOKS is very important. Code is much harder to read then it is to write and other people will struggle if it's written poorly.
To that end you should also comment your code so that other people can follow your logic easier. Look programming style up online.

https://en.wikipedia.org/wiki/Programming_style
>>
ghc: out of memory 
why the fuck does ghc need more than 1gb to compile my program?
>>
>>53925845
what's the problem with for? is it non ideal in this situation or is it a shitty command?
I started learning C last month
I just need help I want to do something I've been a NEET for almost 2 years now...
>>
>>53925900
try it, it wont work.
>>
>>53925900
>I started learning C last month
And you can't write a basic for-loop?
Programming might not be for you.

>I just need help I want to do something I've been a NEET for almost 2 years now...
First order of business, learn the basic, and I mean assignment vs comparator basic, syntax.
>>
>>53925598

M8 you should try to write your code properly. Also don't try to implement everything in one go; if you want to make a program that interviews N users and asks each one 4 questions first make a program that asks one user one question, and then change it to store the answer to the question and so on. Trying to make your program to a bunch of things in one go will turn it into an absolute cluster fuck and you'll probably give up before you learn anything.
>>
>>53925900
that is not how for loop works, at all, you cannot just do shit willy nilly and expect it to work, your code wont compile and for a month of learning you are shit.

I myself only starded duing C earlier this year and after a month I knew how to make a simple cards game.

Takea book, I have read "C Programming: A Modern Approach, 2nd Edition" and read it from cover to cover.

What you are doing right now is painful for everyone involved.
>>
>>53925900
for loops have a very strict way to be set up, and that isn't it. it's for(int x = initialValue; x < targetValue; x=x + increment){ do stuff; }
>>
File: q.jpg (111 KB, 500x500) Image search: [Google]
q.jpg
111 KB, 500x500
So I want to use a sites information in an android app but the site doesn't have any proper api. I have made a library of web scrapers to get all of the information from the site. Should I just use the library in my app or should I host a database of the all the already scraped info and then use simple calls to the database?
>>
Just finished up a couple week long problem.

Had a quiz in my Data Structures class (ECE Major, we have to take some CS classes) where one of the problems was "given the numbers 1 through 7 write a sequence that when put into a binary search tree yields a perfect binary tree." I wrote an answer and thought of a few more, then I decided I would spend that class finding out how many possible answers there were.

The most obvious solution...
from itertools import permutations
from math import *

R = 7

class BinaryTreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None

class BinaryTree:
def __init__(self):
self.root = None

def insert(self, value):
if self.root == None:
self.root = BinaryTreeNode(value)
else:
self._insert(self.root, value)

def _insert(self, curr, value):
if (value < curr.value):
if (curr.left == None):
curr.left = BinaryTreeNode(value)
else:
self._insert(curr.left, value)
else:
if (curr.right == None):
curr.right = BinaryTreeNode(value)
else:
self._insert(curr.right, value)

def _getDepth(self, node, depth):
if (node != None):
n = self._getDepth(node.left, depth + 1)
m = self._getDepth(node.right, depth + 1)
return max(n, m)
else:
return depth

def getDepth(self):
return self._getDepth(self.root, 0)

answers = []
for p in permutations(range(1, R+1), R):
bst = BinaryTree()
for j in p:
bst.insert(j)
if bst.getDepth() == ceil(log(R + 1)/log(2)):
answers.append(p)

print(len(answers))

It finds the answer (80) pretty quickly. Then I tried with with R = 15 for a tree of depth 4. After a half an hour I stopped it.
>>
>>53925900

C and C++ fuck fuck you in the ass for not knowing things that higher level languages will teach you.
Start off with Python and/or Java anon. They will teach you the standards and logic needed to write C and C++ programs efficiently and they have very strict compilers to help you spot your errors.

When you begin to wonder what makes Java work then move to C or C++.
>>
>>53925995
>After a half an hour I stopped it.
why anon ;_;
>>
File: 38286163.jpg (50 KB, 500x365) Image search: [Google]
38286163.jpg
50 KB, 500x365
>>53925936
>>53925950

pls stop...
I just wanted help
>>
I feel like I could replace this with a single function pointer assignment, but maybe that's just because this program is so trivial.

Does this look ok?
void determine_match(pmode_t mode, char *query, char *trip, char *password)
{
switch (mode)
{
case NO_QUERY_MODE: goto print; break;
case CASE_SENSITIVE: if (strstr(trip, query)) goto print; break;
case CASE_AGNOSTIC: if (strcasestr(trip, query)) goto print; break;
default: break;
}
return;

print: fprintf(stdout, "TRIP: '!%s' -> PASS: '%s'\n", trip, password);
}
>>
File: out.webm (191 KB, 608x304) Image search: [Google]
out.webm
191 KB, 608x304
>>53917964
wireworld in D

r8
>>
>>53926030

What
>>53925936
and
>>53925950

are trying to highlight is that whatever the fuck you're doing to learn how to program is not working. You probably need to take a new approach and try to make sure you learn how to do things properly.
>>
File: shrektactular.jpg (2 MB, 927x691) Image search: [Google]
shrektactular.jpg
2 MB, 927x691
>>53926058
That's pretty good
>>
>>53925995
So I thought about a less obvious solution. One that would cut down the computation time. I realized I could make a recursive function that built the perfect tree every time and avoid testing the inputs that weren't perfect, but it would have to enumerate all the trees. Still, a perfect solution.
from sys import argv

rules = dict()
def makerules(x, prevx=0):
global rules
diff = abs(x-prevx)//2
if diff < 1:
rules[x] = frozenset()
return
else:
rules[x] = frozenset((x-diff, x+diff))
makerules(x-diff, x)
makerules(x+diff, x)

count = 0
def m(selectable, chain):
if len(selectable) == 0:
global count
count += 1
else:
global rules
for s in selectable:
m((selectable - {s}) | rules[s], chain | frozenset((s,)))

n = int(argv[1])
makerules(2**(n-1))
m({2**(n-1)}, frozenset({2**(n-1)}))
print(count)

This allowed me to find it for depth 4 (15 elements). 21964800. And that took a minute. Yeah the code isn't optimal, but still, a depth of 5 was out of reach algorithmically.

>>53926027
There are 15! permutations to check. It was dumb to think it would finish this century.
Thread replies: 255
Thread images: 30

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.