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

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

Thread replies: 255
Thread images: 28
File: THERE'S STILL HOPE.png (572 KB, 852x478) Image search: [Google]
THERE'S STILL HOPE.png
572 KB, 852x478
IGNORE ALL NON-PROGRAMMING/POLITICS POSTS

Previous thread: >>52916111

What are you working on, /g/?
>>
ANIMUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU TRAPPPPPPPPPPPPPSSSSSSSSSSSSSSS!
>>
Still fiddling with my idle-game AI. I'm trying to come up with a method of job priority that isn't just an enumerator and counter check.
Perhaps a way to designate "goals" and assigning resource collection based on the goal or something.
>>
>https://losc.ligo.org/s/events/GW150914/GW150914_tutorial.html

LIGO researchers use Python.

Why don't YOU?
>>
int avg(int a, int b) { return a + b / 2; }
did I do good, /g/?
>>
IGNORE ALL PYTHON/SCRIPTING/WEBDEV/BAIT POSTS
>>
>>52921590
Because it's slow
>>
>>52921600
Nice bait mate
>>
>>52921622
rate me fgt!
>>
>>52921590
B-but I do

>>52921611
import numpy as np
>>
>>52921600

avg(2147483647, 2147483647);


Tell me what that produces.
>>
>>52921524
Thanks, this is pointing me in the right direction. I noticed vector was running destructors and reallocting but I didn't put 2 and 2 together and realize it was invalidating that reference. Taking the reference after adding the other element fixed it.
>>
>>52921633
kill yourself
>>
>>52921639
2147483647, as expected
>>
>>52921600
For fuck sakes, 4chan is ded and your code is shit.
>>
>>52921668
what's wrong with it, m8?
>>
>>52921653
http://ideone.com/szrC0Q

kill yourself
>>
Am I missing something? Why would you even bother with REST why you could use RPC? It seems much better on paper.
>>
>>52921691
>unironically using "web apps" to compile
fuck off, shitlord
>>
>>52921680
This is how compiler will see your code.
return a + (b / 2)

because operator / takes precedence over +
>>
>>52921692
>muh soap
>muh wsdl
>muh tag soup
well memed
>>
>>52921653

Try it with INT_MAX instead. You may be using Tru64 Unix.
>>
>>52921720
>got mad for getting told
fuckin no lifer
>>
>>52921729
the nigger is just an arrogant entitled millennial that didn't even run it

notice the lack of parentheses

>>52921744
kill yourself
>>
>>52921713
there are no parentheses in the code, moron
>>
>>52921720
nice argument faglord
>>
>>52921754
people like this are allowed to not die

>>52921759
kill yourself
>>
>>52921729
what is INT_MAX?
>>
>>52921754
kek

so you think this: 2 + 10 /2 is what? 6 ?

fucking retard
>>
File: There_was_an_attempt.png (29 KB, 480x480) Image search: [Google]
There_was_an_attempt.png
29 KB, 480x480
>>52921754
>>
>>52921749
>implying the ability to do better
I dare you fgt
>>
>>52921768
>allowed meme
who's allowing, fgt? who's denying? nothing? thought so
fucking pedophile scum
>>
File: fuckyea.png (32 KB, 472x404) Image search: [Google]
fuckyea.png
32 KB, 472x404
Results of a two-day code clean-up operation: 561 lines deleted, 0 added. All tests pass.

Feels good man.
>>
>>52921790
we've done this a gorillion times already you newfag

i don't remember if this is entirely correct:

int avg(int a, int b) { return a / 2 + b / 2 + (a % 2 + b % 2) / 2; }
>>
>>52921776
yes, do you fucking know math? 2 plus 10 is 12, divided by 2 is 6
you should be banned from /g/
>>
>>52921770

Platform dependent constant that indicates the largest value that can be stored in an int. It's defined in limits.h
>>
>>52921803
our governments you insufferable retard

>>52921820
kill yourself
>>
>>52921816
>don't remember if this is entirely correct
>if
>correct
fuck off with your broken shit; test it first and then come back
>>
File: hipster trash.jpg (47 KB, 400x516) Image search: [Google]
hipster trash.jpg
47 KB, 400x516
>>52921607
Python is turing complete, though.

You're not one of those people who hates things because they're popular, are you? Hmm, if only there was a word for that
>>
>>52921829
>muh government
>do something
>noooo, don't take muh animu, I need to jerk it to kids
fuck off and die in a fire, shitstain!
>>
>>52921834
how about no. how about you test it yourself if you're so interested in averaging two ints in C
>>
>>52921820
grab the calculator and to the math faglord
>>
>>52921847
>needing a calculator for simple addition and division
m8, you might want to leave /g/
>>
>>52921842
all the good languages are more popular than python. you're the real hipster if you think python has any credibility as a programming language
>>
>not using an anime image
>>
>>52921844
>here's some code I threw up
>test it for me, I can't be bothered
>it's good though
fuck off, webshit
>>
>>52921855
https://www.google.com/search?q=2+%2B+10+%2F+6

m8, you might want to kill yourself
>>
>>52921857
>used ubiquitously in data analysis and almost all science fields
>no credibility
lolk
>>
>>52921857
>good languages are more popular than python
so, python is more popular than python? were you dropped?
>if you think python has any credibility
bwahahahahahaha, sure thing, csscuck
>>
>>52921868
as if yours was even half-way decent lmfao
>>
>>52921816

Something like that, except it breaks on integers of different signs IIRC. This is what I use:

#include <stdint.h>

int64_t signed_average(int64_t a, int64_t b)
{
// If a and b are not the same sign, we can safely add without overflow.
if ((a < 0) != (b < 0)) {
return (a + b) / 2;
}

// Otherwise, we take advantage of a particularly useful mathematical
// property: (a + b) / 2 is the same as (a/2) + (b/2). We will use a
// modulus to account for averaging two odd numbers.
else {
return (a/2) + (b/2) + (((a%2) + (b%2)) / 2);
}
}


And as a macro:

#define avg(a,b) ((a<0)^(b<0) ? ((a+b)/2) : ((a/2)+(b/2)+(((a%2)+(b%2))/2)))


Fucking modular arithmetic, man.
>>
>>52921887
sure it was, it's elegant and concise; yours is a pile of shit that most likely doesn't even work
>>
>>52921607
>>
>>52921909
yours barely works, like, at all. did you even run it?
>>
>>52921607
This thread needs less webdev and more anime
>>
>>52921893
#include <stdint.h>

int64_t signed_average(int64_t a, int64_t b)
{
return ((a < 0) != (b < 0)) ? ((a + b) / 2) :
(a/2) + (b/2) + (((a%2) + (b%2))/ 2);
}
>>
File: 3dpd.jpg (192 KB, 480x640) Image search: [Google]
3dpd.jpg
192 KB, 480x640
Is Clojure worth learning? What's the best resource for learning it?
>>
>>52921957
no

how did you even come up with the idea that <obscure meme lang> could possibly be worth learning?
>>
>>52921600
Your code is shit. Observe true autism at work:
int avg(int a, int b)
{
return (a >> 1) + (b >> 1) + (a & b & 1);
}
>>
>>52921982
only works for unsigned integers
>>
What is the masculine programming language and why is it x# with assembly?
>>
>>52921519
trump and sanders are the only decent electable candidates
>>
So, I'm down to learn how to program something, where do I start? Is Code Academy a good place to learn Java/C/C++? Any tips?
>>
>>52922036
codecademy is shit

https://docs.oracle.com/javase/tutorial/
>>
File: c9e.gif (3 MB, 500x500) Image search: [Google]
c9e.gif
3 MB, 500x500
>>52921970
Because this is /dpt/, home of smug anime girls and meme functional programming
>>
>>52922036
Code academy is awful.

Start with python or java. Look up some books you can find online for free

Once you feel good then move on to c++ to learn oop and data structures then never look back
>>
>>52922093
don't start with python

python is shit
>>
>>52922068
We have to defend /dpt/. People are starting to like and post non anime images and we have to do something about it.
>>
>>52922107
Yeah python is shit but to first start out in programming it's probably the easiest to understand due to how liberal the syntax is
>>
>>52922121
This would never have happened if you had just let the trap poster post the new thread every time.
>>
>>52922093
>Start with python or java. Look up some books you can find online for free

Why do you people say this?

Why not just start with C++ and be done with it.
>>
>>52922151
stringency and consistency is better for learning imo
>>
>>52922177
Because starting out with c++ is literally the most difficult thing you could ever do without any knowledge of programming.
>>
>>52921519
I code for the bern
>>
File: when_anime_eat_pizza.webm (3 MB, 800x450) Image search: [Google]
when_anime_eat_pizza.webm
3 MB, 800x450
It's time to ask your beloved programming literate anything.

>>52921790
>>52921816
int average (const int x, const int y) 
{
if ((x > 0) == (y < 0))
return (x + y) / 2;
const int xh = x / 2;
const int yh = y / 2;
const int xhr = x % 2;
const int yhr = y % 2;
return xh + yh + (xhr & yhr);
}


>>52922036
just pick one of the following.

:: Structure and Interpretation of Computer Programs
http://sarabander.github.io/sicp/
http://paste.lisp.org/display/151208/raw

:: How to Design Programs
http://htdp.org/
https://www.edx.org/xseries/systematic-program-design-0

:: Concepts, Techniques, and Models of Computer Programming
not free

:: Composing Programs
http://composingprograms.com/

:: CS for All
http://www.cs.hmc.edu/csforall/
https://www.edx.org/course/cs-all-introduction-computer-science-harveymuddx-cs005x

:: Program Arcade Games With Python And Pygame
http://programarcadegames.com/
>>
>>52922211
How is it more difficult than Java?
>>
>>52922233
Memory management for one.
>>
>>52922177
You start with C.
It has no abstractions that get in the way of learning.
You should never use abstractions without first understanding what you're abstracting away.
>>
>>52922233
java is simpler, stricter, has superior error messages with real-time feedback in the IDE, easy to understand documentation
>>
About what level of knowledge would you consider someone to be 'experienced in' a programming language?

I put on my resume that I'm experienced in C++ and C# because I consider those my "main" languages, but I've never done anything more complicated than a rudimentary text editor in either. I understand a lot of the concepts but working them all together isn't something I've done much of. Will this matter?
>>
>>52922253
but programming is mainly about abstraction.
>>
>>52922036
Start with assembly my man
>>
File: 1437683162905.png (29 KB, 633x758) Image search: [Google]
1437683162905.png
29 KB, 633x758
>tfw too stupid to make an animated decal in libgdx
>the wiki documentation is nonexistant for animated decals
>google doesn't come with anything
>>
>>52921600
The best part of this is that it isn't correct even if you ignore the 'overflow' problem.

If you ask this function to find the average of 8 and 12 it'll return 14.
>>
>>52922274
Programming is about building abstractions.
>>
>>52922273
actually being experienced: 3+ years of working in that language

"experienced" enough to put on a resume: about the same as you because you know everyone else are bullshitting too
>>
>>52922300
Well in that case I guess I'm good. Thanks anon. I assume a job would teach me anything I don't know anyway.
>>
>>52922291
>he fell for the libgdx scam
>>
is anyone aware if pqxx still has memory leaks problems? i am currently compiling with pqxx-4.0 and it still leaks, code is good, it's literally a cycle, tried calling clear and deleting on pqxx::result and it doesn't change, running it on valgrind as of now
>>
>>52921633
muh nigga
>>
File: g user 8.jpg (165 KB, 1440x1440) Image search: [Google]
g user 8.jpg
165 KB, 1440x1440
I got a C test tomorrow. Wish me luck...
>>
>>52922514
show us your code, fukboy.
>>
Fun fact: 90% of the people who hate python don't (or barel) know it
>>
>>52922514
This is what happens when pythonfags write C.

For all you pythonfags out there here's how you would actually write this.

int main(void)
{
int i;
int j;
i = 0;
j = i;
while(0x4)
{
if(j == 0)
{
printf("%i", ++i);
if(i == 5)
{
j = 1;
}
} else {
printf("%d", --i);
if(i == 0)
{
break;
}
}
}
>>
I'm learning to code, is this 'popular culture of the internet' thing legit /g, it's not really mentioned anywhere online. But I got my program to run I guess and it worked, so I must be doing something right. https://www.youtube.com/watch?v=Er6R5R06Q8I
>>
>>52922630
int ctr = 0;
for (; ctr < 5; ctr++)
printf("Counter is at %d\n", ctr);
for (; ctr <= 0; ctr--)
printf("Counter is at %d\n", ctr);
>>
>>52922665
What the fuck is this garbage?
>>
>>52922630
>using break;
>>
>>52922678
Fudged up that there inequality sign.
>>
>>52922665
>python
Dropped.
>>
>
int main(void)
{


WHY PUT A { ON AN INDENT?
>>
>>52922665
the fuck are you talking about
>>
Quastion
why is
    for(int i = 0;i < 5;i++){
printf("%d\n", i);
}

different from
    for(int i = 0;i < 5;i++,printf("%d\n", i))
;
>>
>>52922688
Is he wrong then? I kind of presumed so. I feel pretty dumb for spending the last 15 minutes coming up with the most popular memes on google search trends. It can't be all fake though because it worked, there's an element of truth to it so I think I'll stick with the tutorials
>>
>>52922736
It's an altered Emacs indentation style. In the original brackets were indented twice and the subsequent code blocks were indented twice again. The idea was to solve the dispute between '2-space' against '4-space' by using aspects of both. It actually looks really nice in a properly styled Emacs code block.

Anon went full shitface by making it three spaces instead of two, though.
>>
Does brainfuck use unsigned or signed chars for it's cell array?
>>
>>52921805
>delete functions that are never called
>remember why you added them
>no backups
I'd say something about storage, but even OpenSSH got bit in the ass by old code.
>>
>>52922747
for(pre; cond; post)
i++ is called after the first execution of the loop body
>>
>>52922747
in the sec0ond case the printf is execute at te end of the for

immagine the for as a while loop. the first thing that is executed is the i = 0
then there's the while loop
and then the i++ (and the printf())
>>
>>52922765
What the fuck are you saying?
>>
>>52922747
The second is a compiler error, while the first isn't.
That being said you could easily replace both with

for(int i = 0; i < 5; printf("%d\n", i++)){}


You can do a lot of clever things with For loops in C. The problem is most of those things are, while clever, also very hard to follow and thus bad practice.
>>
>>52922765
No anon he's completely right, faggots in this thread telling you otherwise are normies who have never operated a low level language. 'The popular culture of the internet', i.e memes are an essential part of programming. You need at least 100 memes per program. Stick with the tuts and good luck man
>>
How do I get JavaFX to work in an OSGI Project?
Could use Swing and SWT but JavaFX seems to be a problem because it shows ClassNotFound Exception already at "Class X extends Application".
I just want to Hello the fucking World
>>
>>52922783
~version control~

>>52922798
You are getting memed son.
>>
>>52922772
Anyone who doesn't use
type function()
{
return;
]

style of programming should get shot.
>>
>>52922776
It doesn't matter because 0 is the same in both unsigned and signed and brainfuck has no comparisons that don't use 0.
>>
>>52922808
Ok I will, thanks I guess, I just needed some reassurance. It made sense to me when I watched the video but after I felt a little skeptical, who wouldn't? Well thanks anyway, I think I'll keep watching this series and I want to make a game with what I learn from it
>>
>>52922794
>immagine the for as a while loop
While loops are just gotos. If we're doing syntax insulin here we might as well go all the way.
for(int i = 0; i < 5; ++i) {
printf("%d\n", i);
}

is really just
int i = 0;
a: if(i >= 5) goto b;
printf("%d\n", i);
++i;
goto a;
b:
>>
>>52922830
Anyone who doesn't use
(defun function ()
()
)

style of programming should get shot.
>>
>>52922807
>The second is a compiler error, while the first isn't.

No it is not, it's perfectly legal operation.
>>
>>52922898
Anyone who uses obscure meme languages should get shot. Good luck finding a job >:^)
>>
>>52922872
Yup 10/10
>>
>>52922917
>meme languages
>literally had an entire industry of computers built around them
ok
>>
>>52922830
>not
auto functionname() -> type
{
return;
}


Get out of here with your dinosaur shit. It's not scalable.
>>
Need some technical programming interview questions.
>>
>>52922872
Fucking hell, and they say that /dpt/ is useless, I already learned something very important.
>>
>>52922945
'Here's a whiteboard anon, can you write out a fizzbuzz program in your language of choice? You have ten minutes.'
>>
>>52922935
Basic was used for the BBC micro. But take a look at how many BBC micros are being used today.
>>
>>52922935
"an entire industry" that went belly up within two decades
>>
>>52922736
he is just retarded, don't stare at him or he'll get scared
>>
>>52922955
Yep. And if you want to be REALLY technical, assembly language has a few jump opcodes that have built-in comparators (imagine goto and if combined in one command), they just work slightly different than a typical if. Both goto, while, and for all compile down to these basic jump commands so they're all mechanically identical, even if they're very different syntactically.
>>
Are there any good learning/practice resources for OO design? Books, lectures, etc.

Whenever I try to do a personal project in Java I end up writing most things in static methods. I'm just too used to the procedural style that it seems weird to encapsulate functions within objects, and so I end up ignoring all the other major OO features.
>>
>>52922962
That's a shit example, considering a dialect of BASIC is currently one of the most used programming languages out there.
>>
File: experiments.jpg (23 KB, 435x475) Image search: [Google]
experiments.jpg
23 KB, 435x475
how do i motivate myself to code things?

actually, how do i motivate myself to much of anything?
>>
>>52922957
Easy
def fizzbuzz(num):
if num%15==0: return fizzbuzz(num-1) + "fizzbuzz\n"
if num%3==0: return fizzbuzz(num-1) + "fizz\n"
if num%5==0: return fizzbuzz(num-1) + "buzz\n"
return fizzbuzz(num-1) + str(num)
>>
>>52923019
Step 1 in OOP is to not use Java. It's pants-on-head retarded for basically everything OOP related.

The point of OOP is to have reusable data types, not reusable functions, so forget any idea you ever had about 'static classes'. They're memes.

For a good-example-but-shitty-program example of OOP, think of a program that store bank account information for clients. You would have an 'account' class with various data and functions associated with it, and when a client wanted to open a new account you'd create an instance of the account class with the data they provide. C# is nice for stuff like this, in that it's OOP-oriented but not retarded like Java is.
>>
>>52923066
>recursion
'Sorry anon, you're too white for this job.'
>>
>>52923066
I'm a HR person, since this doesn't match the Java code snippet I got from the programmers you failed.
>>
>>52923027
>a drag and drop simulator is a programming language
>>
File: shia.jpg (44 KB, 800x465) Image search: [Google]
shia.jpg
44 KB, 800x465
>>52923063
just make it so
>>
>>52923066
>>> fizzbuzz(10000000)
RecursionError: maximum recursion depth exceeded in comparison

you didn't get the job
>>
>>52923116
t. python
>>
>>52923019
>Whenever I try to do a personal project in Java I end up writing most things in static methods.
Don't do this, first of all.

If you want a fun personal project, try making an MMO. I know that sounds like bullshit advice, but I don't mean you should make an actual playable MMO. Just hook your program up to a database (another important thing to learn about), and write classes for things like characters and stats, inventories, items that can be stored in those inventories and so on.
You don't even need to be able to connect any clients to it, just the server portion is enough for OOP design practice, but if you want to you can learn some network programming by letting clients connect and trade items or gold with eachother.
Obviously this isn't a suggestion for beginners but since you have experience with procedural style languages you could probably do this.
>>
>>52923176
>no TCO support
What are you coding in, java?
>>
>>52923066
print(["FizzBuzz" if i % 15 == 0 else "Fizz" if i % 3 == 0 else "Buzz" if i % 5 == 0 else i for i in range(1, 100)])
>>
File: fizzbuzz.jpg (103 KB, 1075x1689) Image search: [Google]
fizzbuzz.jpg
103 KB, 1075x1689
>>52922957
>>
>>52923229
he posted python
>>
>>52923238
work on your handwriting
>>
>>52923255
If there's one thing I like more than shitting on python it's shitting on java.
>>
>>52921982
>>52921995
let's not forget that it compiles into the exact same thing if you specify unsigned int
>>
Are you using memes in your programs /g?
https://www.youtube.com/watch?v=Er6R5R06Q8I
>>
>>52923176
from sys import setrecursionlimit
setrecursionlimit(10**999999999999 ** 99999999999)

That should be enough recursion.

>>52923236
Remove the brackets and you'll get a slightly more optimized version
What you have is equivalent to
print(list("FizzBuzz" if i % 15 == 0 else "Fizz" if i % 3 == 0 else "Buzz" if i % 5 == 0 else i for i in range(1, 100)))
>>
>>52923019
>end up writing most things in static methods
Fun fact: in modern Java development you usually don't make a method static even if you can (because it hinders dependency injection)
>>
Is this a proper use of the switch statement?
bfuck_t interpret_cmd(const char c)
{
bfuck_t cmd;
switch (c)
{
case '>': cmd = INCREMENT_PTR; break;
case '<': cmd = DECREMENT_PTR; break;
case '+': cmd = INCREMENT_DATA; break;
case '-': cmd = DECREMENT_DATA; break;
case '.': cmd = OUTPUT_DATA; break;
case ',': cmd = ACCEPT_DATA; break;
case '[': cmd = LEFT_BRACKET; break;
case ']': cmd = RIGHT_BRACKET; break;
default : cmd = INVALID_COMMAND; break;
}
return cmd;
}
>>
>>52923063
>how do i motivate myself to code things?
wtf, that's like asking "how do I motive myself to go to the bathroom". Just wait a day or so until the urge to program is so strong you can no longer bear it.

If that doesn't happen, quit CS
>>
>>52923372
yeah, arguments and stuff like that are all a switch statement is really used for since each case does something completely different.
>>
>>52923329
>>> from sys import setrecursionlimit
>>> setrecursionlimit(10**999999999999 ** 99999999999)
OverflowError: Python int too large to convert to C long

come on anon, you can do better than this.
>>
>>52921519
>ignore all politics posts
>OP
guess I'm outta here
>>
>>52923423
/ has precedence over - you tard
>>
>>52923388
I've been coding for years, I used to have those kinds of urges.

Nowadays I just get uncaring when I try to code.

I guess I'm just broken, is this not normal?
>>
File: nM8S4yb.jpg (609 KB, 4160x3120) Image search: [Google]
nM8S4yb.jpg
609 KB, 4160x3120
>>52923238
>using more than one line
your code wouldn't even fit on a small enough whiteboard, senpai
pic related is what you should have wrote
>>
>>52923476
You're clinically depressed.
>>
>>52923566
Stop, you are giving me flashbacks to writing out 15 pages of java code by hand for my college exams.
>>
>>52923590
I've been thinking so, I've just been needing someone else to tell me it.

What should I do? I'd like to code things again.

Is there an (effective) alternative to a psychiatrist?
>>
File: Selection_094.png (6 KB, 336x95) Image search: [Google]
Selection_094.png
6 KB, 336x95
What does this code do, /g/?
>>
>>52923591
Wow, seriously? For my class the programs or functions we wrote always fit on one page.
>>
>>52923644
>Is there an (effective) alternative to a psychiatrist?
Not really. Drugs can make you believe it isn't real but they can't actually help you.
>>
>>52922227
>literate
>can't average 2 ints
end yourself pedofag
>>
>>52923646
i still prefer slides to
>>
What does the comma operator do in brainfuck?
Where is it getting it's data from?
>>
>>52923646
It's undefined behaviour.
>>
>>52923672
Our finals were 6 hour exams. For some of them I ended up with 10-15 pages of "code" that looked like >>52923566
Not all for one problem though, I'm talking about for the entire exam.
>>
>>52923723
stdin, usually.
>>
>>52923727
Obviously. I'm just ondering what it actually DOES.
>>
>>52923646
adds x to itself and x + 1. increments x a total of three times

returns x + 1. increments twice more.
>>
>>52923773
Then compile and run it you dumb fuck.
>>
>>52922036
Sololearn.com
>>
>>52922318
>>52922291
What's wrong with libgdx?
>>
>>52923773
It's undefined behaviour, which means that there are no meaningful results.
>>
>>52923750
so it accepts 1 byte during runtime?
Do you stop the program and ask the user for that byte?
>>
>>52923673
I'm just going to have to do it.

Thanks anon, I've been needing this for a long time.
>>
>>52923780
It just gives me errors. I adjusted it to an error-free version, which isn't quite as interesting:
int goes_to_very_quickly(int x) {
int *px = &x;
++*px++;
*px++ += *px++ + ++*px;
return px++;
}

int main(int argc, char *argv) {
printf("%i\n%i\n%i\n", goes_to_very_quickly(1), goes_to_very_quickly(5), goes_to_very_quickly(100));
return 0;
}


This compiled successfully and wrote the following to stdout:

328752648
328752648
328752648



I'm satisfied.
>>
>>52923823
It works almost exactly the same as C's getchar() function.
>>
>>52923644
>>52923644
Exercise. Eat. healthy. Set up a daily routine. Set goals. Do something different for awhile.

You can take pills but it may take several months to find something that really hits the spot. Then you have to justify it. Its a facade. It only deters your depression. You'll be hiked up on more and more.
>>
Daily reminder: objects
>>
>>52923113
But you said language of choice!
I demand to see the manager.
>>
>>52923936
I'm so far gone that anything a bit hard I just go meh on, definitely after though once I can get myself in order I will do that.
>>
File: 1364508011124.jpg (75 KB, 600x688) Image search: [Google]
1364508011124.jpg
75 KB, 600x688
Using C#:

Resources A, B, C, and D exist.
Workers collect resources A and B.
It is determined Building 1 needs to be built.
Building 1 (and all other building objects) and stored within a dictionary.
Inside that dictionary is another dictionary of Resource requirements (rather than just using a list of KeyValuePair. Same thing).
There is a separate dictionary of Worker Jobs, each of which specifying what Resource the jobs collects.

How should I pair all this shit up if Building 1 requires resource C and D instead of A and B?
My ideal is that I examine my current resource stockpile of C and D to determine which has the closer % to fulfilling Building 1's requirements (trivial enough), then assigning workers in a 1:1 ratio (for now) to collect those resources.
I'm stuck on the assignment part though. I can't think of a logic pattern to find out what resource is needed, then find what job produces that, then assign a worker to it.
>>
Where you guys learned to code?
>>
>>52924060
School. Hobbies. General boredom. Literally pick up a book and see if it clicks.
>>52924031
Then enjoy that ridiculously tedious road to get the proper pills to get your life in order. Hopefully you only need to start on Zoloft 50mg and that does it for you. Because getting on and off pills takes two months of time, then more appointments to get different pills so you can start over. It's a bitch.
>>
File: 1451431535166.jpg (35 KB, 561x365) Image search: [Google]
1451431535166.jpg
35 KB, 561x365
>>52923646
Reminds me of
>>
should I kill myself, dpt?
>>
>>52924118
Only if you want to do that. Are you incapable of learning something new and finding meaning to life?
>>
>>52924058
Make a datastructure that maps resources to the job that produces them, like a Dictionary<Resource, Job> for example?
>>
>>52924136
>meaning to life

Life has no meaning faggot
>>
>>52924136
no, but my material and social conditions make it difficult. also, I've wasted, like, 10 years of my life being a dumb fuck

anyway, I was expeting an automatic "yes"
>>
Threadly reminder that you should not refer to the act of programming as coding. It is improper and makes you look like a 16 year old

You are a programmer, not a coder

Software Alchemist is GOAT
Developer is okay
Magician is okay
Software Magus is okay
Software Engineer is okay
Software Architect is okay
Code Guru is questionable

Archmage is reserved for only the most senior of programmers

Writing in HTML and CSS is not programming, therefore it should be referred to as designing
>>
File: 1435878721912.gif (842 KB, 280x224) Image search: [Google]
1435878721912.gif
842 KB, 280x224
>>52924058
None of this makes sense. Is this even proper English?
Are you trying to program a video game?
Are you trying to program a work/resource simulator?
Are you trying to program an optimization algorithm for work/load balance?

What the flying fuck are you even trying to do?

In any case, parallel processing is tricky. Each resource, worker, building should be a class, and each collection too. Also you will need external thread manager classes if you want proper OOP. But since you write like an Indian

>It is determined Building 1 needs to be built.

I can't give any further advice.
>>
>>52924137
Is there any way to create such a thing without having to duplicate the Job/Resource dictionary data?
The dictionaries in question also hold information such as number of filled jobs, current rate of resource collection, etc. and are updated from different spots.
>>
>>52922747
i would increment before printf.
>>
>>52922630
>while(0x4)

LMAOOOOOO
>>
>>52924183
Do you not know how to understand variable names or something?
All resources share the same characteristics, each one being its own class (of which there would then be 50) is retarded.
Same for workers.
Same for buildings.
This isn't multi-threaded, it's a basic AI on a tick-based system, so fucking around with threads is totally unnecessary.

Why the building has to be built is irrelevant to the question.
>>
>>52924174
>>52924174
Well I'm not a therapist or anything, so I guess if you want to kill yourself, go right ahead.
>>
>>52923209
>java

:^) nice meme brother
>>
I'm trying to roughly calculate the minimal requirements for something I'm writing but can't be bothered to actually benchmark the thing on a bunch of different platforms. I know there are many different hardware architectures which change how many cycles a given sequence of instructions typically takes but on average, assuming no user-installed programs running in the background and no automatic updating, how many cycles does Windows 7/8/10 consume passively? Is it a significant number? Am I asking the wrong questions?
>>
>>52924176
How about Technowitch?
>>
>>52921727
this
>>
>>52924194
>Is there any way to create such a thing without having to duplicate the Job/Resource dictionary data?
You would want to use references to the jobs and resources, so they wouldn't really be duplicates. I can't really speak to your specific case, that's just the first thing that came to mind. But if the Resource->Job required mapping stays constant (i.e. you don't suddenly get a different resource from a job), then this might be a pretty simple and elegant way of doing it.
>>
>>52924382
I don't know why I didn't think to use references. I think this'll put me on the right way, thanks
>>
How do I get better at programming?

I've gotten to the point where all the shit on those ideas pictures are either way too easy for me, and so I learn nothing, or are so difficult I don't even know where to start.
>>
>>52921600

?
average: ;fastcall ecx,edx
push ebp
mov ebp,esp

mov [esp-04h],ecx
mov [esp-08h],edx

fild dword[esp-04h]
fild dword[esp-08h]
faddp

mov dword[esp-04h],2
fild dword[esp-04h]
fdivp
fist dword[esp-04h]

mov eax,[esp-04h]

mov esp,ebp
pop ebp
ret


All of your problems are fixed in assembly. No more ambiguity. Join us.
>>
>>52924117
'x++ += x++ + ++x' and the goes-to-very-quickly operator both came out of the same codeshare. slides-to was a subsequent meme.

I was there for it all, anon. I've seen things most programmers can't even dream of.
>>
>>52924452
mate I'm the man who wrote the slides to operator, watch your tongue
>>
I am learning programming and I want to make a relatively video game. The premise is basically Civilization meets Tamagachi meets a little Dwarf Fortress. (AI civilizations interacting in a virtual world with limited user interaction and lots of detailed information to read that runs 24/7.) I then want to put this on a raspberry pi with a touch screen, battery, and some sensors.

I want to learn using a language like Scheme/Haskell because I own some books on them and I really like what people say about them, but if that is dumb I would like some suggestions on what I should use.

I am in University and I am currently taking the CSIII class for an idea of my experience level, my biggest project was 800 lines in Java and I want practice working on something bigger.
>>
>>52924513
*relatively large
>>
>>52924292
> Am I asking the wrong questions?
Yup.

Unless you have something significant running in the background, background CPU usage is likely to be less than 1%.

Also, when it comes to "cycles", accessing memory might take one cycle (if the memory is in the cache), up to a few dozen cycles (if the memory isn't in the cache, depends upon whether it has to wait for an existing transfer to complete), or millions of cycles (if the memory is paged/swapped out and has to be read from disk).

IOW, the only remotely accurate way to gauge performance is to actually measure it.
>>
>>52924510
How does it feel to be the world's worst shitgrammer?
Your puny "operator" has nothing on the apocalypses-to operator!
int main((void)void) {
for(int i *********[[[
****]]]]
***]]]
**]]
*]
0] //i apocalypses to 0 very quickly
) {
printf("%i", i);
}
}
>>
>>52924513
C++/Lua

Scheme/Haskell will use paradigms your probably not familiar with
>>
>>52924544
This was very helpful. Thank you.
>>
>>52924549
Your operator is potent I must say, but it is simply not meme material.
>>
>>52922697
>Not using language features.
>>
>>52924563
Paradigms like what?

I know some things, I read about 30% of Learn you a Haskell for great good and some scheme shit.
>>
>>52924432
You program your own ideas or you google the stuff you don't know? But if you have to ask then I have my doubts as to your ability to self-teach.
>>
>>52922630
That braces, OMG WHY.
>>
>>52921519
I don't get your picture.
Also, you're a faggot.
>>
>>52922630
>uses both %i and %d
Why?
>>
>>52924636
Not that guy but I put braces on the same column because my autism forces me to.
>>
>>52922937
> What is this crap.
Withness me!
auto func = [] { return ":P"; };
>>
File: 4413246790_da5f8b7e68.jpg (66 KB, 312x312) Image search: [Google]
4413246790_da5f8b7e68.jpg
66 KB, 312x312
>>52922630
if(i == 0)
{
break;
}
>>
I'm learning python, and I got a project which requires me to do google image search with an image. Is there any way to do this ? I've searched google but it's not really helpful.
>>
>>52921519
holy shit bernie got 60% and trump only got 35%? why even have the election trump's gonna lose
>>
>>52922630
Tried for a serious attempt since I'm still learning C.
#include <stdio.h>

int main( int argc, char **argv)
{
int i = 1;
for(; i < 6; ++i)
printf("%d\n",i);
for(; i > 0; --i)
printf("%d\n",i);
}
>>
>>52924723
you're retarded
>>
>>52924717
What exactly are you trying to do? Search for images based on text, images based on images, or are you simply trying to utilize google image search in your own program? If the latter take a look at https://developers.google.com/web-search/docs/

>>52924432
>so difficult I don't even know where to start.
These are the problems you NEED to do to get better. Of course you don't know where to start, you haven't tried figuring it out. Pick a project that looks fun then figure out how to go about doing it. If you need to be pushed in the right direction just ask here, but try figuring it out on your own first.
>>
>>52924717
https://developers.google.com/custom-search/json-api/v1/reference/cse/list#try-it
>>
>>52924762
Compact your shit senpai.
main() {
for(int i = 1; i < 6; ++i) printf("%d\n", i);
for(; i > -1; --i) printf("%d\n", i);
}


When using gcc, printf is an implied expansion so you don't need to include stdio.h just for it. Also, both the 'int' and the arguments to main are unnecessary.

You can golf this even more if you wanted to:

main()
{for(int i = 1; ++i < 5;) printf("%i\n", i);
for(;i-->0;) printf("%i\n", i);}
>>
>>52924848
>This is good programming sempai.
Don't listen to this brat. Write proper readable code.
>>
>>52924848
Won't compile with my compiler.
>>
>>52924848
Unless C is shit, the i is out of scope of the second loop.
>>
>>52924563
Why lua?
>>
I have this quick app that i wanna make for android and iOS, any useful tools for multiplataform development? Free, preferably.

Tried QT but i don't really like it.
>>
>>52924891
>multiplataform development?
HTML 5 >>>/wdg/
>>
>>52924870
>>52924876
Shit, you're right the i would be out of scope.
So that needs to be fixed.

I think it's also possible that some compilers won't like the "-->" so that should probably be fixed too.

If I remember correctly implied arguments still work in C03, so this should work.

main(i) {
for(i = 1;++i < 6;) printf("%i\n", i);
for(;--i > 0;) printf("%i\n", i);
}
>>
>>52924848
When initializing the variable inside the for loop, it goes out of scope as soon as it ends
for(int i=1; 1<6; i++) {}

printf("%d",i); //error
>>
>>52924891
Write it in c++ and then cross-compile.
>>
>>52924432
I'd recommend starting here, start with the really difficult stuff that even university graduates can learn from, you'll be a programming God in no time https://www.youtube.com/watch?v=Er6R5R06Q8I
>>
>>52924915
>>52924920
Won't compile with my compiler.
>>
>>52924934
Meme yourself.
>>
>>52924946
You sure? What's the error?
>>
File: oh god help.png (161 KB, 1052x690) Image search: [Google]
oh god help.png
161 KB, 1052x690
>>52924934
>mfw
>>
>>52921639
fuck off tripfag
>>
>>52924848
You can't code for shit. good job.
>>
>>52924915
Just actually compiled this to see if it works. It does, but it starts at 2 due to an oversight.
Here's the corrected code:
main(i) {
for(--i; ++i < 6;) printf("%i\n", i);
for(; --i > 0;) printf("%i\n", i);
}
>>
>>52924796
In short, the program i'm doing scrapes image from imgur, and then determine what if it's an image of cats (or porn, or whatever) using keywords found in the google result page when you search that particular image.
To be honnest, i just need a way to code an image search in python, and i'll deal with the rest.
>>52924814
I'll look into that, thanks.
>>
>>52923322
it doesn't give the correct output for all signed ints
>>
>>52925022
Won't compile with my compiler.
Thread replies: 255
Thread images: 28

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.