[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: 14
File: DPT.png (389 KB, 934x1000) Image search: [Google]
DPT.png
389 KB, 934x1000
Old thread: >>51806401

What are you working on /g/?
>>
The one true pic.
>>
>>51810647
First for Julia
>>
Somewhat proficient programmer here

What language should I use for game dev? Hopefully something with both OO and functional programming functionality, I find functional makes a lot of common video game dev design patterns a lot more versatile, like Control

>>51810671
Use your code tags
>>
File: round cubes.webm (766 KB, 799x598) Image search: [Google]
round cubes.webm
766 KB, 799x598
>>51810647
round cubes
>>
Comments? Figured I had never written a merge sort so wrote this down on my phone in 10 minutes.

def mergesort(l):
if len(l)<16:
return isort(l)
else:
return merge(mergesort(l[:len(l)//2]), mergesort(l[len(l)//2:]))

def merge(l1, l2):
print(l1,l2)
t=list()
i1=0
i2=0
while i1<len(l1) and i2<len(l2):
if l1[i1]<l2[i2]:
t.append(l1[i1])
i1+=1
else:
t.append(l2[i2])
i2+=1
if i1<len(l1): t+=l1[i1:]
elif i2<len(l2): t+=l2[i2:]
return t

def isort(l):
i=1
while i<len(l):
j=i
while j>0:
if l[j-1]>l[j]:
swap(l, j-1, j)
j-=1
else:
break
i+=1
return l

def swap(l, i1, i2):
l[i1]+=l[i2]
l[i2]=l[i1]-l[i2]
l[i1]-=l[i2]


Also I'm breaking PEP8 by using 2 spaces for indention but the phone screen is kinda small

>>51810685
Forgot to throw them in
>>
>>51810685
c++
>>
>>51810685
Literally C++, it's got OOP, functional, and it's fast
>>
>>51810685
F#
>>
>>51810722
It's also shit
>>
>>51810740
he wants to make a game lol lmao
>>
>>51810685
>>51810722
That or Rust
Or D if you're an epic memer
>>
>>51810767
>D is a meme
>Rust isn't one
ok kid
>>
D!
>>
>>51810706
I have no interest in reading it until you make it pep-compliant and you name l1/l2 as a/b.
>>
Do you think this is ugly?
void adjust_lights(P_MODE mode, int (*arr)[SZ][SZ], POINT from, POINT to)
{
unsigned i, j;
for (i = from.x; i <= to.x; i++) /* x */
{
for (j = from.y; j <= to.y; j++) /* y */
{
switch (mode)
{
case toggle:
(*arr)[i][j] += 2; break;
case turn_on:
(*arr)[i][j] += 1; break;
case turn_off:
{
(*arr)[i][j] -= 1;
if ((*arr)[i][j] < 0)
(*arr)[i][j] = 0;
break; /* brightness cannot be negative */
}
default: break;
}
}
}
}
>>
>>51810794
l1 is a lot more descriptive than a
>>
File: 03892f98687cfd0fc1d251be37a7c9bc.jpg (400 KB, 1920x1080) Image search: [Google]
03892f98687cfd0fc1d251be37a7c9bc.jpg
400 KB, 1920x1080
I'm trying to make a platform game using phaser.js but am stuck trying to make my music loop.

A guy on stackoverflow sent me a link which shows the correct code :

http://jsfiddle.net/edf2362f/

But It wont work for me, I don't understand what the wall of text after ''var sndFile'' = means


Any help?
>>
while(1) {
printf("Please don't use an anime image next time!\n");
}
>>
>>51810812
the breaks should be on new lines.
>>
>>51810705
fuck i wish i was on whatever you're on
>>51810706
the fact you did this on your phone is impressive enough.
>>
>>51810821
var sndFile
contains the raw audio.
>>
>>51810774
At least you can actually use Rust without a GC and not lose most of the standard library
>>
>>51810812
>P_MODE and POINT as types
>Not declaring i and j inside the for loop declaration
>Unnecessary level on indirection with (*arr)[SZ][SZ]
>5 levels of indentation
>Two statements on the same line
3/10
>>
>>51810819
Hungarian notation is shit. Use type annotation or a docstring and then use a variable name that isn't horrific l1l2l2l1l2l1l1l2l1 pollution. I hope you know that using `l' as a variable isn't even permitted in PEP.
>>
>>51810844
So how would I replace that with a file of my own?

Im a total noob in case you hadn't noticed
>>
>>51810892
It isn't to signify the datatype, it's just list 1 and list 2. The datatype just happens to share the name. So it isn't hungarian notation.

Now, I think you should use a better font instead of complaining about my l's.
>>
>>51810812
><=
no
>>
>>51810897
http://phaser.io/docs/2.4.4/Phaser.SoundManager.html
It sounds like it's a wrapper around an HTML5 audio tag.
>>
>>51810685
Sepples ofc.
>>
Not directly related to programming: How do you learn best, /dpt/? For me, I have to be able to move my hands to visualise what I'm thinking about, or else things don't stick.
>>
>>51810685
C++14 or Rust
>>
>>51810993
/prog/ memes are cringey at this point
>>
>>51810974
I have a better font (terminus) but that doesn't mean your names are PEP8-compliant or that they aren't shit.
>>
>>51811014
I usually masturbate before/during/after learning.
>>
>>51811014
Use pen and paper to draw logic.
>>
>>51811014
for stuff I need to understand - visualisation and actually working with it
for college classes (memorisation) - voice recording of the text played in a loop
to lesser extent handwritten notes for both
>>
>>51811014
I learn best by teaching others
>>
In Python, if I have a list like
["string", ["string2", "string3"], "string4"]

How do I remove that inner list, so it is just one single list with four strings like
["string", "string2", "string3", "string4"]
>>
>>51811098
This is a great way to do it. I often imagine explaining it to someone else and imagining what questions they may ask. It's a great way to find the holes in your understanding
>>
So, does anyone on this korean site know how to average 2 ints? Last thread contained no solution.
>>
>>51810988
I have no idea how to implement this
>>
>>51811098
The best way to debug something is to walk through it like you're explaining it to someone else.
>>
>>51811119
I think lists have a built-in flatten method (so if a is your list run a.flatten()). Otherwise, Google how to flatten (that's the correct term) lists in Python.
>>
>>51811153
Look up a project on Github that uses Phaser. Steal the audio part.
>>
fuck you
>>
>>51811130
a/2 + b/2 + (a & b & 1)


However, this is patented so you have to license it.

This is free to use I think:

low + (high - low)/2
>>
>>51811187
you too lmao
>>
>>51811226
But neither of those work.
>>
>>51811228
i wasn't talking to you you you idiot
>>
>>51811252
Why?
>>
fuck you. yeah. YOU
>>
>>51811265
Because they're wrong.
>>
>>51811319
lolnou
>>
>>51811252
They do though. I'm starting to think it's YOU that doesn't know how to average 2 ints.
>>
>>51811346
not you. HIM
>>
>>51811226
god bless the USA
>>
>>51811158

Ahh, thanks. I was googling with "implode" and "explode" because I had no clue what the word was, I've got it now.
>>
>>51811360
Classic mistake for someone that doesn't know C. Have you ever heard about overflow and undefined behavior?
>>
>>51811226
>6 operations is faster than 3
yeah nah
>>
>>51811406
>faster
doesn't matter if it's incorrect
>>
>>51811395
Those specifically take steps to avoid that problem

Jesus Christ
>>
>>51811395
Thinking you know C is a classic mistake people who don't know C make. >>51811226's solution works in more cases then your non-existent one.
>>
>>51811440
They don't though.
>>
>>51811363
Imagine if you could patent a + b and then sue every developer in the world, or at least in the US.
>>
>>51811457
>works in more cases
>not working in all cases
bwahahahahaha
>>
>>51811468
everyone would use b + c
>>
>>51811457
>I don't know C
that's obvious already
>>
>>51811395
Thought mods remove 100% full-mode trolling?
>>
template <typename T>
std::enable_if<sizeof(T) < sizeof(int64_t)>::type
average(const T a, const T b, std::enable_if)
{
int64_t sum = a + b;
return sum / 2;
}
>>
File: 1279684593119.gif (164 KB, 240x246) Image search: [Google]
1279684593119.gif
164 KB, 240x246
a/2 + b/2 + (a%2 + b%2)/2
>>
>>51811510
Woops, disregard the third argument, I was initially thinking of doing it in a different way but anyway will work for all integer types whose sizeof() is less than sizeof(int64_t) ;^)
>>
>>51811511
Thanks Hitler, you always had the best solutions.
>>
>>51811531
nobody cares, that's not C
>>
>>51811511
>>51811536
The final solution
>>
>>51811495
>this is over my head
we know, css dude, we know
>>
>>51811476
We already know which approach is more valid in C, see C99, C11, etc.
>>
>>51811570
>already know
but you don't know shit, m8...
>>
>>51811545
whatever here's a rough equivalent in the downgraded garbage that C is:
#include <stdint.h>

int64_t avg8(int8_t a, int8_t b)
{
int64_t sum = a + b;
return sum / 2;
}

int64_t avg16(int16_t a, int16_t b)
{
int64_t sum = a + b;
return sum / 2;
}

int64_t avg32(int32_t a, int32_t b)
{
int64_t sum = a + b;
return sum / 2;
}
>>
>>51811476
all > some
>>
>>51811590
some > none
>>
>>51811588
as expected, it doesn't work
>>
>>51811590
>>51811597
ITT the kids on /g/ learn about partial orders
>>
File: bb.png (20 KB, 1280x720) Image search: [Google]
bb.png
20 KB, 1280x720
shooting bouncy bullets is kinda fun but time to work on some real collision stuffs and add enemies
>>
>>51811020
Rust is viable for game development?
>>
>>51811621
Not him, but for what cases doesn't that work?
>>
>>51811226
I thought we were dealing with ints, not unsigned ints.

& on signed integers is implementation-defined (and the implementation is allowed to "define" it as undefined).
>>
>>51811646
No.
>>
>>51811646
Do OpenGL bindings exist?
>>
>>51811226
>this is patented

what? you can patent one line of code???
>>
>>51807648
>being this useless
>blaming the distro for it
>>
>>51811703
In the land of freedom you can do anything
>>
Any cool github projects to contribute to? I have some spare time this weekend
>>
>>51810647
/!\ REMINDER /!\


As per the 4chan /g/dpt/-15 standard
all new threads must be POSIX
compliant.
As such, the use of anime images,
including, but not limited to,
manga, hentai, anime, fanart or
graphic novels, is forbidden, and a
punishable offense.

Please post this warning whenever
a new thread may be about to be
created. The /g/dpt commitee
thanks you!

/!\ REMINDER /!\
>>
>>51811698
https://github.com/bjz/gl-rs
>>
>>51811723
Except, of course, use that line of code
>>
>>51811511
>>51811536
>>51811549
doesn't work
>>
>>51811672
It doesn't work for the cases where the sum overflows. It should be e.g.:
int64_t sum = (int64_t) a + b;

Otherwise, the addition will be performed using the original result, then the possibly-overflowed garbage result (if it doesn't just trap) will be promoted to 64 bits.

But even with that fix, it doesn't answer the original question, which just said "integers". Nothing prohibits "int" from being 64 bits, and such platforms actually exist.
>>
>>51811748
>doesn't work
care to explain why?
>>
>>51811728
https://github.com/xiph/daala
>>
>>51811763
try a = -1 and b = 2
>>
File: jas.png (61 KB, 617x587) Image search: [Google]
jas.png
61 KB, 617x587
what the hell am i doing wrong. they are being run sequentially, not in parallel. the threads also seem to be running being i .start() them.


import threading
from time import sleep

counter = 0

def incre():
global counter
for x in range(5):
counter += 1
print counter
sleep(1)

def checker():
global counter
while counter != 5:
print "\ncheck"
sleep(.5)
print "priv checked"

thread1 = threading.Thread(incre())
thread2 = threading.Thread(checker())


thread1.start()
thread2.start()

>>
>>51811766
Looks cool, thanks.
>>
>>51811798
You're calling the functions you idiot
>>
Mission Impossible - Averaging 2 ints in C: The Thread
>>
>>51811757
ebin, simply ebin m8

https://ideone.com/jJxe7d
>>
http://dustycloud.org/blog/code-of-copylefts/
>>
is the average thing a meme?

masterrace
(a + b) << b & (a + b) << a
>>
>>51811784
Usually you're working with index numbers or something otherwise you would just use floating point
>>
>>51811823
try css
>>
File: 1441082264835.jpg (83 KB, 305x810) Image search: [Google]
1441082264835.jpg
83 KB, 305x810
>>51811818
you've fixed everything
>>
>>51811858
>backpedaling
>>
>>51811798
change
thread1 = threading.Thread(incre())

to
thread1 = threading.Thread(target=incre)
>>
Man, C must be a really shit language if it can't even average two ints.
>>
>>51811867
ideone is overloaded atm and is glitching, anyway you're full of shit at
>It doesn't work for the cases where the sum overflows.

because int64_t sum = a + b; doesn't overflow even if you specify 127 as a and 127 as b
>>
>>51811856
you don't know what the fuck you're talking about, right?
>>
How easy did y'all find day 7 of AoC? I'm looking at the challenge and input and think I may be overthinking it
>>
>>51811901

does anyone in this thread?
>>
>>51811856
see >>51811784
>>
>>51811898
>doesn't overflow even if
you're out of your element, htmlcuk
>>
>>51811921
it was quite simple once I actually re-read the instructions at figured that I can't provide signal to a wire when it's unknown rather than providing 0 as a default

>>51811940
if it overflows then how come it works? :^)
>>
>>51811898
>overloaded atm and is glitching
>%s for formating an int64_t
m8...
>>
>>51811950
>i tested these 2 carefully chosen values and got the expected result
>it just werks
end yourself
>>
(a&b)+((a^b)>>1)
>>
>>51811898
>I can't read compile errors
gtfo
>>
>>51811921
It was the hardest for me, but still easy. You just loop and check which assignments can be figured out and delete them off your list until "a" is found. An assignment is possible if all its inputs are in a list of solved inputs or a number
>>
>>51811979
yeh i typo'd and quickly corrected but the change didn't go through, i'm sure you've never ever made a typo in your life

>>51811998
i chose two highest possible values for int8_t specifically to demonstrate that you can perform addition this way and they won't overflow without casting either side
>>
>>51812007
doesn't werk
>>
>>51811950
>>51812019
Oh good, that makes it way more manageable then
>>
none of these int calculations even matter when you can get .5 at the end

just do

a/2.0 + b/2.0


and call it a day
>>
I suck at math and logic.

How do I improve? Practice? Reading books?

>inb4 you don't
>>
>>51812017
see the first part of >>51812020
>>
>>51812020
>values for int8_t specifically to demonstrate
we're talking about int overflow, try to keep up, js monkey
>they won't overflow without casting
try larger values
>>
>>51812053
math can be learned
if you can't wrap your head around things like conditional statements and logic gates, consider studying liberal arts instead.
>>
>>51812020
>sure you've never ever made a typo
did you also typo the parameter names to main? fuck off, muppet
>>
>>51812053
You try to solve problems, I guess.

I mean if your issue not with any language you have to practice the other part of programming, which is problem solving, you learn logic by applying logic, I'd suggest looking at http://adventofcode.com/

Also math is math, it just has to be learned, you aren't going to rediscover calculus.
>>
>>51811119
may I ask why you need to do this? I literally cannot think of a single case where I needed to flatten a list like this. reduce(+) is cleaner and doesn't fuck your shit up unexpectedly.
>>
>>51812049
still not guaranteed to work
>>
>>51812049
Not good enough for a 64-bit int (a double typically only has a 53-bit significand).
>>
>>51812068
>we're talking about int overflow, try to keep up, js monkey
int8_t is an integer and this will work for all fixed width integers that are < sizeof(int64_t), and because there's so much shit around a simple averaging in C it just shows that C is as much of a garbage that the JS you're complaining about

>try larger values
larger values for what? for the input integers that are of fixed width of 8 bits? are you really this dumb?

>>51812092
>did you also typo the parameter names to main? fuck off, muppet
i'm primarily using C++, not my fault that C is such a garbage the compiler complains about unnamed parameters
>>
>>51811226
4/10
>>
>>51812130
>this will work for all fixed width integers that are < sizeof(int64_t)
no
>>
What are the best data structures and why are they binary trees?
>>
>>51812106
>>51812108
yeah fuck you guys, I'll just not ever average 2 numbers
>>
>>51812130
>i'm primarily using C++
hahahahahah! you don't even know C and you're using C++? you're completely lost, mate!
>>
>>51812164
The stack is a 10/10
>>
>>51812162
Skip lists
>>
>>51812192
>meme lists
>>
>>51812157
yes

>>51812171
>hahahahahah! you don't even know C and you're using C++? you're completely lost, mate!
you don't need to know C in order to write C++, this is a common misconception, actually learning C before modern C++ would be considered harmful
>>
int avgnoov (int si_a, int si_b)
{
if ((si_b > 0) && (si_a > (INT_MAX - si_b)))
{
/* will overflow, so use difference method */
/* both si_a and si_b > 0;
we want difference also > 0
so rounding works correctly */
if (si_a >= si_b)
return si_b + (si_a - si_b) / 2;
else
return si_a + (si_b - si_a) / 2;
}
else if ((si_b < 0) && (si_a < (INT_MIN - si_b)))
{
/* will overflow, so use difference method */
/* both si_a and si_b < 0;
we want difference also < 0
so rounding works correctly */
if (si_a <= si_b)
return si_b + (si_a - si_b) / 2;
else
return si_a + (si_b - si_a) / 2;
}
else
{
/* the addition will not overflow */
return (si_a + si_b) / 2;
}
}
>>
>>51812130
>confuses int with int8_t
confirmed html copy paster
>>
>>51812192
not clearly recursive; irrelevant
>>
>>51812205
>don't need to know C in order to write C++
integer promotion rules are the same in both; the fact you don't know about them in C, also shows us your C++ level: shit
>>
I just wanted to post that I masturbate to /g/uys talking nerdy.

carry on
>>
>>51812246
*unzips zygohistomorphic prepromorphism*
*destroys your initial algebra*
>>
>>51812221
You can implement binary trees without recursion and you can implement skip lists with recursion
>>
>>51812208
looks legit; no wonder the rest of these faggots can't get it right
>>
How do I know the lenght (How many characters) of a file that was opened with fstream in c++? I want to try and solve the first day of Advent of Code by using a for loop that reads a text file with the puzzle input and then adds or subtracts from a "result" integer depending on what character it reads.
>>
>>51811898
> because int64_t sum = a + b; doesn't overflow even if you specify 127 as a and 127 as b
Try the 32-bit version (or the 16-bit version on systems with a 16-bit int).

Integer types smaller than int are automatically promoted to int prior to the calculation, and int is guaranteed to be at least 16 bits.
>>
>>51812197
>meme trees
>>
>>51812273
Hence the clearly part. The most natural way to operate on trees involves recursion, not iteration, and vice-versa for skip lists. That's why trees are better.
>>
>>51812282
b-but muh C++ knowledge
>>
>>51812162
Binomial heaps are very cool

Also DAFSA and tries

>>51812297
Recursion isn't inherently better
>>
>>51812294
yes, they are
>>
>>51812297
>muh stack overflow
>>
Objective-C++â„¢
>>
>>51812320
>Recursion isn't inherently better
opinion discarded
>>
>>51812351
lotta code for a hired programmer
>>
>>51812280
Open it with ate mode (at end) and then use tellg (gets the current position).

Seems like a better idea just to open it, and use a while loop to read each character until you encounter eof.
>>
>>51812351
Wha kind of project is that?
>>
I understand 2D triangular arrays. Is it possible to create 3D or higher triangular arrays?
>>
>>51812445
What the fuck is a triangular array? An array of arrays which are smaller than each other?

If so, sure you can.
>>
>>51811898
>>51812282
REKT
E
K
T
>>
>>51812445
Index 0,1 and 1,0 will return the same value.

Array memory footprint is cut in half (best case).
>>
Fuck man, I'm trying to read PPPC++ but I can't seem to manage to understand shit.

Stuff just doesn't get inside my head.

Is it a better idea to learn a different language before trying C++?
>>
>>51812533
the fuck is PPP
>>
>>51812533
C
>>
just use python guys
>>
>>51812543
Programing Principles and Practice using C++
>>
File: Shutter 2015-11-06 21:20:45.png (291 KB, 1424x1176) Image search: [Google]
Shutter 2015-11-06 21:20:45.png
291 KB, 1424x1176
>>51812397
Cross-platform application framework. It's still pretty rough right now, but I'm making good progress.
>>
>>51812533
Learn C first. Otherwise you end like this faggot >>51812205 that thinks he knows C++ and then getting rekt like this >>51812239
>>
File: bjarne2.jpg (25 KB, 293x324) Image search: [Google]
bjarne2.jpg
25 KB, 293x324
>C++ isn't the most patrician language
why are you not using C++ /g/?
>>
>>51812558
just learn C++ from online tutorials

>>51812574
you learn the parts of C you really need along the way
telling someone to learn C first is really useless
>>
>>51812605
What tutorials would you recommend?
>>
>>51812625
http://www.cplusplus.com/doc/tutorial/
>>
>>51812533
don't listen to >>51812574 or you'll be thinking of c++ as c with classes which is a dangerous misconception.
>>
>>51812657
these tutorials teach the bare minimum of c++. anon should get a good book instead
>>
>>51812574
>>51812551
>>51812687
>>51812657
>>51812605
>>51812665


What do then?
>>
>>51812697
Buy "The C++ Programming Language"
>>
>>51812720
How dense is it? I mean, what are the chances of my brain exploding while reading it?
>>
>>51812697
learn from those tutorials then read the PPP book
>>
>>51812726
Not high, it is moderately dense I would say.
>>
In C#, if my class library uses an external .dll, do I need to ship this external .dll with every application that is developed using my library as well?
>>
File: 1439737404042.jpg (56 KB, 576x379) Image search: [Google]
1439737404042.jpg
56 KB, 576x379
>>51812351
>>
>>51812741
Only if you want it to work.
>>
>>51812600
are you really asking this after proof that /g/weebs can't even average 2 numbers in C?
>>
>>51812103

I was actually trying to do the Day 6 problem in AdventOfCode which is coincidentally mentioned in the post above yours. Splitting the string up gave me lines in the form of:

['toggle', ['780', '318'], ['975', '495']]


and I didn't want to have to type line[1][0] in order to get the first co-ordinate. also I've been reading about reduce() and itertools chaining and list comprehension and discovered all kinds of

[item for sublist in [sublist if isinstance(sublist, list) else [sublist] for sublist in l] for item in sublist]


shit that makes my head want to fucking explode it's just a simple thing why do i need to know absurd arcane syntax with no documentation to do such a simple fucking task, i have still actually yet to solve this problem i've just settled for using line[1][0] notation
>>
>>51812741

C# has no concept of static linking and NET.Native isn't a thing yet so yeah, you are stuck shipping this external .dll.

It sucks HOW MUCH we do dynamic linking in the software world.
>>
>>51812856
I would say how we handle dynamic linking is what sucks.

No inherent versioning, no way (that I know of) to automatically package a full binary up.
>>
Is it valid to do this in C#?
double foo = dict.TryGetValue(key, out foo) ? foo : 7.5;


dict is a Dictionary<int, double> and key is an int.
>>
>>51812902
if TryGetValue returns a bool, and it's similar to C syntax then yeah it should work
>>
>>51812902
Wouldn't it be great if there were a way to test if code compiles and then runs properly?
>>
I just got around to starting to learn to programme today, I'm trying to learn Java on CodeAccademy, I do fine in the bits of work it asks you to do, I'm still on entry level though, if struggling a tiny bit in some places.

But I just don't feel like I'm taking the information in. Anyone got any advice for learning to programme?

Also, what is a Boolean? It's thrown that word around a lot, is it just a question with a True or False answer?
>>
How do I read a .csv file using visual studio for c++ and input new values for certain sections of the table sheet?
>>
>>51813000
A boolean value is either true or false
>>
>>51813000
well for starters you could actually try and put in some effort
>>
>>51813000
>CodeAccademy
codecademy is shit m8. IMO, they "teach" by throwing semi-random facts, without any good explanation. just read a book. for example, python.org has a book that guides you. not sure how it is for noobs, but I guess it's good enough.
>>
>>51813105
>python
don't listen to this guy
>>
>>51812750
Eh, it's an interesting language. But these NeXTSTEP/Cocoa names are pretty cancer.
>>
So /g/, can you average 2 int numbers in C?
>>
>>51813125
it doesn't look interesting
>>
>>51813000

Learn to google a lot, and I mean an absurd amount. A Boolean is a lightweight data type that is always set to either true or false.

Also Codeacademy is a slick website, but is a very bad place to actually teach you things. It's the equivalent of putting a 4 year old on your lap in a car and he holds the steering wheel and you tell him "see! you're driving! wow!" Everything is already set up for you, and you're just trying to get to the next screen rather than learn anything. Learning to program is just trying to solve problems in efficient ways. You should probably start with Python because it is very good and beginner oriented, also there are a tonne of youtube video tutorials out there with good, fun beginner guidelines for stuff you can do.
>>
>>51813151
>lightweight data type that is always set to either true or false

why can't you just say
a boolean value is either true or false

why you write wall of text, are mexican?
>>
>>51813126
Same way you would in real life. Add them together and divide by two.
>>
>>51813126
No, it's been well proven at this point, that we can't.
>>
>>51813116
Could you not?

Learning Python as a newfag won't make it harder or impossible to learn new languages. When I was younger I learnt Python, and now I'm learning C++ without any problem.

Python might be shit for big projects, but it's perfect for beginners.
>>
>>51813139
I'm interested in language design and stuff; I find an OOP language based around message passing neat. But in practice it just makes code less readable — it makes formatting difficult and seems to encourage meandering one-liners.
>>
Is it possible to read and write a .xls file using visual studio for c++?
>>
>>51813165

Because you can get a boolean utility out of any other data type like an integer that you check is set to either 0 or 1 or a string set to yes or no, but we don't use these types because it's retarded and wastes resources.
>>
>>51813205
Booleans are usually implemented using ints because ints are generally the fastest integer size of the platform
>>
>>51813204
you can write what every you want, as long as you know the format
>>
>>51813185
That's because in the world of programmers everyone is looking for a silver bullet, and when something works, people try to make it work everywhere.

At a certain level of complexity, everything is a network problem, so at the highest level of a complex system, message passing is needed. That doesn't mean it works for every part of a language.
>>
import std.stdio;
import std.string;
import std.conv;

void performOP(string op, in int op1, in int op2, out int result)
{
switch(op)
{
case "AND":
result = op1 & op2;
break;
case "OR":
result = op1 | op2;
break;
case "RSHIFT":
result = op1 >> op2;
break;
case "LSHIFT":
result = op1 << op2;
break;
default:
break;
}
}

void main(string[] args)
{
File file = File(args[1], "r");
int[string] vars;
int op1, op2, result;

while("a" !in vars)
{
file.rewind();
while(!file.eof())
{
string[] line = split(chomp(file.readln()));
if(line.length == 5)
{
if((line[0] in vars || isNumeric(line[0])) && (line[2] in vars || isNumeric(line[2])))
{
op1 = isNumeric(line[0]) ? to!int(line[0]) : vars[line[0]];
op2 = isNumeric(line[2]) ? to!int(line[2]) : vars[line[2]];
performOP(line[1], op1, op2, result);
vars[line[4]] = result;
}
}
else if(line.length == 4)
{
if(line[1] in vars)
{
result = ~vars[line[1]];
vars[line[3]] = result;
}
}
else
{
if(line[0] in vars || isNumeric(line[0]))
{
vars[line[2]] = isNumeric(line[0]) ? to!int(line[0]) : vars[line[0]];
}
}
}
}

writeln(vars["a"]);
}


My solution for day 7 of AoC
>>
>>51813229
Yeah, ObjC could have done just as well by just calling them methods like everyone else, having a more readable syntax, and just doing exactly the same thing under the hood as it does now. The
[ object message ]
format just screams "we want to be different" to me, especially since it was supposedly intended as a descendant of C.
>>
So I'm writing a game in C++ and the jist is that two ship fight each other. So there is a weapon class that's an attribute to the ship class. The ship class has a function called "battle" in which two ships fight each other. The weapons for each respective ship have different fire rates and damages levels. The problem I'm encountering is that I want a ship to "fire" upon another ship as soon as it is available to fire, but instead the program waits for one ship to fire and then allows the second to fire (the battle is happening sequentially instead of continuously). Is there a way to force the program to execute a function based on it's timing rather than it's position within this function?


void Spaceship::Battle(Spaceship &a){
while(this->GetCurrentHullStrength() > 0 && a.GetCurrentHullStrength() > 0){
this->Fire(a);
a.Fire(*this);
}
}

void Spaceship::Fire(Spaceship &a){
int HullStrength = a.GetCurrentHullStrength();
/*I'm sure I can come up with a more efficient way to do the below calculation*/
int dam = GetWeapon().GetWeaponDamage();
int NewHull = HullStrength - dam;
Sleep(this->Port1.GetRateofFire());
a.SetCurrentHullStrength(NewHull);
cout << a.GetName() << ": Current hull strength is " << a.GetCurrentHullStrength() << endl;
/*cout << this->GetName() << endl;*/
}



let me know if you have any questions
>>
>>51813126
can you?

>>51813116
it was an example, you fucking faggot.

>>51813183
you can have whole websites written in python... ex: django.
>>
When will the "Hurr durr Python is good for nothing" meme die off?

Seriously, Python might not be capable of making an OS from scratch, but it's nice for projects that don't involve fucking around with memory or doing CPU intensive bullshit
>>
>>51813183
You can't unlearn Python. It ruins you for life.

>>51813205
still would've been better to say
a boolean value is either true or false

>>51813260
if that's D, you realise you could do this, right?
void performOP(string op)(in int op1, in int op2, out int result)
{
mixin("result = op1 " ~ op ~ " op2;");
}

performOP!">>"(3, 4, result);
>>
>>51813346
>You can't unlearn Python
Why even unlearn it when you can literally learn another language? Seriously, it's not like you need to "delete" a language from your brain before learning a new one.
>>
>>51813361
retards like him/her can't just learn new langs... he's mad because he was taught java and couldn't learn anything else.
>>
>>51812834
int avg(int a, int b) {
int *r;
if (__builtin_add_overflow(a, b, r)) {
return (*r>>1) | (1<<31);
} else {
return (*r>>1)
}
}
>>
>>51813306
If you look at your Fire function, it calls Sleep
If instead of that, you have an extra variable that counts how long it's been since it's fired, you can move the timing elsewhere and pass the deltatime (the change in time / the time step) as a parameter to Battle
>>
>>51813361
>>51813391
Holy fucking shit what is this.
DPT is currently a Python circle jerk.

Python is shit and will make you shit for life, get over it.
>>
>>51813335
> Python might not be capable of making an OS from scratch
Don't give them any ideas
>>
>>51813419
What do you get out of shitposting like this?
>>
>>51813361
it's true tho
if you start off with a babby mode language that encourages expensive operations. it takes ages to unlearn that shit.
>>
>>51813419
>Someone is talking about a language I don't like
>ABLOBLOO CIRCLE JERK

Get over it, there aren't just 2 languages out there.
>>
>>51813174
>I don't know how
webfgt
>>
>>51813401
doesn't work
>>
>>51813306
>>51813403
if battle is the only thing where real time is important:

while(this->GetCurrentHullStrength() > 0 && a.GetCurrentHullStrength() > 0)
{
this->tryFire(a, 5);
a.tryFire(*this, 5);
sleep(5);
}
/*
tryFire is like Fire, only it takes the amount of time that has passed, updates the gun cooldown and only fires if the cooldown is over
*/

(will give this a single shot advantage though)
>>
>>51813476
why not?
>>
>>51813485
(you write tryFire. you need an extra attribute for the cooldown.)
>>
>>51813436
No it doesn't. It takes trying to make a program fast and profiling.

Once something shows up when profiling and you see the real speed, it doesn't take long to understand the real cost of things.
>>
>>51813501
That's just his memey response. It works, if you can compile it that is.
>>
>>51813505
>it takes trying to make a program fast

P Y T H O N
Y
T
H
O
N
>>
>Start reading "The C++ Programming Language: 4th Edition"
>"Oh this isn't so complicated"
>Reach page 47
>"OH GOD WHAT DOES THIS EVEN MEAN"

My brain hurts
>>
>>51813594
>C++
>my brain hurts
working as intended
>>
>>51813594
what's it on
>>
could someone help me with my maths a bit?
with
a^2 + b^2 = c^2
why is it that
c = sqrt(a + b)
rather than
c = (a + b) / c
>>
>>51813346
Oh shit, thanks anon
>>
>>51813637
you mean a^2 + b^2
>>
>>51813616
User-Defined Types, structures, classes, enumerations, etc.

I just wanted to accomplish my dream of making an OS before dying of a caffeine overdose at age 48
>>
What's the best language to learn for a beginner? I was going to go with Java.
>>
>>51813655
that's not that bad
what's confusing you?
>>
>>51813654
yeah, sorry

with
a^2 + b^2 = c^2
why is it that
c = sqrt(a^2 + b^2)
rather than
c = (a^2 + b^2) / c
>>
>>51813637
it's c = sqrt(a^2 + b^2), you sqrt both sides of the equation. sqrt(c^2) = c, but you can't reduce sqrt(a^2 + b^2).
Thread replies: 255
Thread images: 14

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.