[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: 36
File: froggu.jpg (101 KB, 400x600) Image search: [Google]
froggu.jpg
101 KB, 400x600
Froggu Edition

Previous Thread -> >>54137762

What are you working on today /g/?
>>
>>54146482
voxel engine with ray tracing in vulkan
>>
File: 1460899891386.gif (48 KB, 2034x1491) Image search: [Google]
1460899891386.gif
48 KB, 2034x1491
>Posting a thread before the bump limit
>>
File: 1448041267522.png (55 KB, 800x1033) Image search: [Google]
1448041267522.png
55 KB, 800x1033
I decided I don't wanna work today, so I called my manager and took the day off and now I'm gonna play vidya and read internets all day long.
>>
Anyone know a way to increment an integer every third iteration in a loop, without using control statements?
>>
>>54146516
for (int i = 0; i < n; i += 1/3) {
...
}

:^)
>>
File: swift.webm (3 MB, 640x1183) Image search: [Google]
swift.webm
3 MB, 640x1183
>>54146482
r8 my calculator /g/, do you like the design?
>>
>>54146516
>>54146565
>>
>>54146571
That would just output
num_initial +0
num_initial +1
num_initial +2


as i % 3 = 0, 1 and then 2, over and over
>>
File: ama.webm (2 MB, 1280x720) Image search: [Google]
ama.webm
2 MB, 1280x720
Ask your favorite programming literate anything (IAMA)

>>54146571
your code does

+ 0
+ 1
+ 2
+ 0
+ 1
+ 2
...

not

+0
+0
+1
+0
+0
+1
...

>>54146505
git ?
>>
File: coldcolafreezebrain.webm (2 MB, 1172x652) Image search: [Google]
coldcolafreezebrain.webm
2 MB, 1172x652
>>54146516
i := 0
a := 0

while ...
a +:= (++i % 3) = 2
>>
>>54146701
maybe when it's done. I know a smidge about raytracing but vulkan is completely new to me.
>>
>>54146516

>>54146655
>>54146701
tfw I'm fucking dumb.

num = num_initial + floor(i/3)
>>
>>54146812
what you meant to do was
number += (i%3==0);
>>
>>54146812
That works. Thank you~~
Question is, would it be faster to just put in an if.

Time for testing
>>
>>54146866
> would it be faster
I think so.
>>
>>54146848
>i%3==0);
only if loop start at 1
>>
I'm learning programming at the moment.

What is the best way to pull a specific value from a website and have that included in a program? (is there a name for it)

For example it would read out the stock price for certain securities from the asx website.
>>
>>54146866
If you were doing it every nth iteration for large(ish) n, the if statement would probably be faster since branch prediction will just assume the increment branch isn't taken most of the time and just skip the conditional altogether. For every 3rd iteration, it's harder to tell.
>>
>>54146909
If the website has an API, use that. Otherwise, it's a painstaking process that even experienced programmers have trouble with.
>>
>>54146866
not that I totally believe it, but have you ever heard of what they say about premature optimization?
>>
>>54146866
what would be the if ?
>>
>>54146909
reverse engineering,
>>
>>54146970
if(i == 3) pixelIndex++;


I'm iterating through a bunch of bytes.
Each byte is broken down into 8 bits.

In a nested loop, each bit is inserted a color channel of an RGB pixel. This means a byte of data is effectively spread out over 3 pixels
Byte1=(RGB RGB RG)
Byte2=(B RGB RGB R)
And so on.

So, for every three bits, I need to increment the pixel index. But this if happens for every bit in each byte.
That's 8 * number of bytes. Bunch of ifs.
>>
>>54146909
python with the beautiful soup package should be able to do what you want with relative ease.

>>54146945
>html parsing is a painstaking process that experienced programmers have trouble with
maybe in 1994
>>
>>54147054
but you have to reset i to 0 then
>>
>>54146898
number += ((i+1)%3);

happy now? I knew someone would bring this garbage up.
>>
>>54147087
but what your code does now is
+ 1
+ 2
+ 0
+ 1
...
>>
>>54147081
Sorry, it's like this actually.

if(++maskIndex % 3 == 2) pixelIndex++;

I keep the bitmasks in an array. The bitmasks are just numbers representing the LSB of each color channel.
>>
>>54146506
>animuuuuuuuuuuuuuuuuuuu
>>
>>54147103
fuck hold on
number = ((i+1)%3==0);
>>
>>54146532
wtf
>>
>>54146532
>commas instead of periods
>in spanish

fucking dropped
>>
>>54147119
you aren't incrementing it breh.

don't worry... you'll get there...
>>
File: 1440364053732.jpg (25 KB, 500x327) Image search: [Google]
1440364053732.jpg
25 KB, 500x327
>>54146532
>dat lang
>>
File: 320402394.jpg (82 KB, 680x680) Image search: [Google]
320402394.jpg
82 KB, 680x680
>>54146532
>pi hotkeyed instead of e
stay beaner
>>
>>54147203
BUILD A WALL
>>
>>54146701
Shit, was was the name of this anime?
>>
>>54147268
>Loli death: The anime
It was shit
>>
>>54146482
while(true) {
System.out.println("ANUS! ANUS! ANUS!");
}
>>
>>54147288
Yes
>>
>>54147296
no
>>
>>54147268
Naruto
>>
>>54147320
maybe
>>
So I have a bunch of bookmarks that I want to send to my phone.
and I was thinking of creating simple http server using python, and copy pasting the links to html file.
Good?
>>
>>54147327
i don't know, can you repeat the question?
>>
>>54147220
fixed, thanks for the advice
>>
>>54147354
no problem paco.

real calculators should never have pi builtin, users should have to use ln(-1)/i instead.
>>
File: gnu+linux.jpg (737 KB, 1090x1500) Image search: [Google]
gnu+linux.jpg
737 KB, 1090x1500
>student account still active despite finished degree
>probably going to be disabled soon
>tfw no more god-like free ebook service through all the connected publishers (Pearson, O'Reilly, Springer, Wiley, etc.)


What pricey/hard-to-find books to grab before this happens?
>>
https://www.youtube.com/watch?v=DleT-jBp5Q0&feature

Do you guys watch this? it's really fun and light.
>>
>>54147456
just grab every single thing you wanna study.
>>
>>54146516
I+=0.33333 :^)
>>
>>54147437
lol wat

func pressButtomPi() {
return ln(-1)/i
}


I mean, what's the difference?
>>
>>54147519
one less sign of the existence of filthy greek people, thats the difference
>>
>>54147565
What's your problem with them?
>>
>>54147596
they smell bad and they put cucumbers on everything
>>
File: index.png (1 MB, 1462x1506) Image search: [Google]
index.png
1 MB, 1462x1506
https://myvs.azurewebsites.net/#/build-avatar
>>
File: kekcat1.gif (2 MB, 500x284) Image search: [Google]
kekcat1.gif
2 MB, 500x284
How are other platforms than PCs and smartphones programmed? I'm talking about platforms like GameBoys, digital cameras, some car interfaces, and so on.
>>
Just figured out how to solve the Travelling salesman problem in linear time
>>
>>54147870
They're embedded systems, so, at least gameboy games were programmed in assembly languages like for the Zilog Z80 CPU (Inside the gameboy)
>>
>>54147892
What about stuff like digital cameras and modern car interfaces?
>>
File: comments not formatting right.png (32 KB, 1287x526) Image search: [Google]
comments not formatting right.png
32 KB, 1287x526
I mean I know this code is going to be retarded, its not an actual problem with the code. I need this fixed though because I'm getting cancer from looking at my code.

http://pastebin.com/EXveMSQ4
is the code for reference.

I've tried return keying early instead of letting the comments word wrap and that didn't do anything. I've tried reformatting it too using Edit -> Advanced -> Format Document. I can nigger fix it by just having a shorter comment like the comment above but that seems like an awfully stupid fix. Please tell me there is a way to fix this /g/ senpai.
>>
Beginner programmer here, learning Python at the moment.

I've got a function that I'm meant to call to display some ASCII art, however I'm not sure how to actual call it.
By all means, feel free to laugh and call me retarded.

The function is: http://pastebin.com/V9VL3wV5

And it needs to be called after the user agrees to run the program.


#Asks the user if they would like to play
agreement = str(input("Would you like to play Petals Around the Rose [y|n]?"))

#If user types y or Y, the game continues
if agreement in ['y', 'Y',]:

display_dice(dice)

#If the user type n or N, the game exits
elif agreement in ['n', 'N']:
print("No worries! Another time perhaps!")


>>
>>54148022
..just put the documentation on multiple lines? split at 80 or 120 chars?

depending on the version, pressing enter will keep the indent and insert the triple slash

also, break at sentence or idea boundaries.

it'll hide all but the first line, but if you mouse over it it'll expand (and it'll be fully expanded in intellisense, or you can expand the region manually (clicking or with a keybind)
>>
>>54148063
>tfw fixed it by moving the documentation to <example> Documentation </example> and works right in intellisense. Thank you for your post, it gave me the idea to look for more comment formatting sections.
>>
with regex isnt (L|E|D|G|Y)* the same as ([LEDGY])*
>>
>>54148141
yes for single characters, [] creates a character class that allows for ranges while | (OR) will allow for multiple OR matches. [] matches a single character in the range, | matches the LHS or RHS

(abc|edf) would not be the same as [abcdef] nor would it would be the same as [a-c]|[d-f]. because [ .. ] will match a single character in the constraint
>>
>>54148034

Okay scratch this, I was being seriously retarded. I thought I already had die1 and so on declared, but naw
>>
>>54148182
oh yes, I see. thank you
>>
>>54148197
cant you just put
import random
while True:
agreement = str(input()).lower()
if agreement == 'y':
print('answer')
break
elif agreement == 'n':
print('answer')
break
print("please give answer")

if agreement == 'y':
print(random.randint(0,6))
.
>>
File: Capture.png (2 KB, 403x117) Image search: [Google]
Capture.png
2 KB, 403x117
>>54148257
Unfortunately I'm not allowed to change that part of the code.

Next question though.
Each time the die are rolled, 5 numbers, and their associated dice graphic are displayed. It's broken up into three rows. How could I go about counting only what's on the top and bottom row, and only if the middle row contains an asterisks?
>>
>>54147268
boku no pico
>>
File: 1457356334210.jpg (88 KB, 587x443) Image search: [Google]
1457356334210.jpg
88 KB, 587x443
Here's a list of my skills. What should I learn next?

Coding:
>C++
>C
>Assembly
>Lua
>Python
>Some C#

Web:
>PHP and JavaScript languages
>HTML5 and CSS
>Ajax
>Bootstrap
>WordPress
>Drupal
>A good understanding of most common web exploit types

Networks:
>A good understanding of network architecture and common exploit types (ranging from DNS poisoning and MAC spoofing to Kerberos attacks).
>However, a lack of knowledge regarding the brands of equipment and their specifics.

Low-level and hardware:
>Some understanding of how the OS is booted (and consequently, the relationships between the BIOS, the bootloader, and the bootable device).
>A good understanding of the Portable Executable structure.
>A good, low-level understanding of how programs are executed (what processor registers come into play, how the program is presented in memory, and so on).
>Some understanding of general CPU and computer architecture.

Misc:
>101 cryptography understanding (including hashing, crystallographic protocols, etc.)
>>
>>54147884
Time is linear except for string and multiverse theory.
>>
>>54148552
install gentoo
>>
>>54148552
Fucking spellcheck
correcting the last part to "cryptographic protocols"
>>
>>54146532
>,
>>
>>54148559
Are you an idiot? He's talking about algorithmic time complexity. Many algorithms, for example, run in polynomial time - that is, their big-O is polynomial.
>>
I need to make an audio recorder for Android that plays an audioclip and records the echo of it at the same time. I'm calling recording start when the clip finishes playing, but the MediaRecorder keeps crashing because the recorder apparently didn't have enough time to record anything. The clip in question is 0.25 seconds long.

Any idea what I could do? After extensive googling, it seems no one else has come upon this problem.
>>
>>54148593
The user will be able to change it in the settings, amerifags will get "." as default.
>>
>>54148601
>being this new
It was an obvioua b8, retard
>>
>>54148552
More C#.

Database knowledge would really round this out.

Get a basic understanding of TSQL and rudimentary setup and architecture of databases in SQL Server and MySQL, including performance tuning (indexes, query tuning, etc.).
>>
>>54148625
>settings. amerifags
FTFY
>>
File: 1451479764011.jpg (35 KB, 537x198) Image search: [Google]
1451479764011.jpg
35 KB, 537x198
>>54148627
>>
>>54148625
>default,
FTFY also
>>
>>54148625
How do you third-worlders write
1,500.34
>>
>>54148672
1.500,34
obviously,
>>
>>54148672
Many european countries use spaces instead of commas and commas instead of dots
Git gud
>>
>>54148552
actually build something worthwhile instead of ranting out these "skills" you have
>>
>>54148687
Jesus christ.
>>
>>54148695
This
These webfags never learn their place
>>>/g/wdg
>>
>>54148694
>spaces instead of commas
Absolutely disgusting,
>>
>>54148712
9gag tier
>>
>>54148672
Australian here.
1500.34
is the ONLY correct way to do it. If you do it any other way, you should hang yourself.
>>
>>54148712
>>54148737
Samefagging this hard
>>
Let's say I have 3 objects
object_1=Number_Class (100)
object 2=Number_Class (200)
object 3= Number_Class (300)


How would I add all the numbers in the object up?
>>
>>54148747
Clarify yourself, the question is ambigous
>>
>>54148742
What made you think I was trying to be someone else?
In fact what makes you think those two posts you linked are even related to each other besides being posted by the same person?
Are you retarded? or are you just trying to fit in?
>>
>>54148759
I'm using python 3 and I want to take the value that each object has (100,200,300) and add them all up, my bad if it's unclear I'm just getting the hang of all the terms
>>
>>54148747
How is your class declared?

Why are you using a class that appears to be equivalent of a primitive?

You should just write extension methods for the primitive if that's really why you're doing this.

You would have implemented an Add() method for your class, otherwise, you can explicitly convert to a primitive like int and go from there.
>>
>>54148762
Nice b8
>>
>>54148792
Yep, you're both retarded and trying to fit in.
>>
>>54148672
1 500,34
1.500,34
1,500.34

It is a shitshow, really.
Worst part is when you work with people who use excel. That fucker translates everything from functions to decimal places.
Sometimes the translation fails, and I receive some gibberish.
It is a pain.
Just use english for all programming.
It will make everything easier for everyone.
>>
>>54148801
>Just use english for all programming.
>It will make everything easier for everyone.
1,000,000 times this.
>>
Why does it matter what methods are named? Why would it be negative if a method is named main?
>>
>>54148790
What's a primitive? All my teacher taught me to do was to create classes and objects, then made us figure out the rest.

This is how I created my class
class Bank_Account:
def __init__(self, x, y):
self.initial_balance = x
self.acc_name = y
def deposit(self,x):
self.initial_balance += x
self.final_balance = "$" + str('%.2f' % self.initial_balance )
print(self.final_balance, self.acc_name)

#example object

object_1 = (100, "Ben")
object_1.deposit(100)
>>
>>54148834
Right, so just how you created your 'deposit' method, you would also need to create an 'add' method to add two bank accounts together.

Rather than assuming the same behavior as integer addition, you create your own addition that may do something special, like log the addition somewhere.
>>
>>54148834
>>54148857
To expand on this, it almost sounds like you want to 'merge' accounts here. One account should be removed, right? What happens when you merge two accounts?

Alternatively, you could be trying to add to one in a 'transfer'. One account gets 100 from another account. You'll need to make sure the seed account is deducted. Can't create money from nothing, eh?
>>
>>54148823
some languages require the entry point to a binary be called main.

for example in C++ ::main must be in the global namespace, cannot be a member function and all kinds of rules
in Go, main() tells the compiler that that package is a binar

etc.

basically some compilers for some languages look for 'main' to create an entry point for a special type of output file. they probably won't compile if you try to use it as some other function/method but it all depends on your language/runtime/compiler/interpreter

why is it 'negative?' because you're overloading a well known method name to do something else, might or might not work. ymmv
>>
>>54146482
if (!OP.image.contains(Subjects::Programming))
throw std::runtime_error("OP is a fag");
>>
>>54148902
op here, dubs confirm I'm not a fag.
>>
>>54147165
>in spanish
That's not spanish
>>
>>54148902
>Uses C++, the literal meme lang
>Tries to call somebody else a fag
>>
>>54148933
Noice.
>>
>>54148695
I completed lots of projects over my programming career.

>>54148705
Are you an idiot? Most of these skills aren't web development related. Perhaps, you're too dumb to understand what they even mean. Or just a jealous insecure brainlet.
>>
>>54148980
Go back to /b/
>>
>>54148980
Literally go back.
>>
File: regex.png (23 KB, 501x476) Image search: [Google]
regex.png
23 KB, 501x476
am I so stupid?
I cant even figure this out
>>
>>54149108
link to this one, I've done lots of these
>>
>>54148899
Good shit, thanks lad.
>>
>>54149157
https://regexcrossword.com/challenges/doublecross/puzzles/4
>>
public static void Main(Vector<Integer> l);{
int a = 0;{
for(int i = 0; i < l.size(); ++i) {
if((i) < 3) {
++a;
}
}
return a;
}

public static void main(final String[] args) {
Vector<Integer> vector = new Vector<Integer>();
Random random = new Random();
for(int i = 0; i < 1000; ++i) {
vector.add(random.nextInt(7) + 1);
}
System.out.println(ltThree(vector));
}
}

My teacher tells me to change this so that the vector isnt an object but an int[]
Please help me with this, it's in java lby the way.
>>
>>54149245
1. Don't call your other method Main lmao
2. Where is "ItThree()"?? You called your other method Main
3. read your compiler errors
>>
>>54149245
holy shit kill ur self
>>
File: Capture.png (5 KB, 432x231) Image search: [Google]
Capture.png
5 KB, 432x231
>>54148522 here,

Trying to re-create Petals around the rose (https://en.wikipedia.org/wiki/Petals_Around_the_Rose)

I'm seriously going full retard tonight. Instead of reading the asterisks, I can just take the dice value which is stored in die1, die2 etc.

I figured that would be simple enough; if the number is 1 or an even number on any dice, I'd make the score for that dice return 0. If the dice returned 3 or 5, I'd make the score return dieResult = dieResult -1.

The plan was to do that for all five dice, then take the new sum of each dice and add them. I was going to do that with the following, but the answer is always incorrect (see pic related). Am I overlooking something really stupid?

    if die1 == 3 or 5:
die1res = die1 - 1
else:
die1res = 0

if die2 == 3 or 5:
die2res = die2 - 1
else:
die2res = 0

if die3 == 3 or 5:
die3res = die3 - 1
else:
die3res = 0

if die4 == 3 or 5:
die4res = die4 - 1
else:
die4res = 0

if die5 == 3 or 5:
die5res = die5 -1
else:
die5res = 0

result = die1res + die2res + die3res + die4res + die5res
>>
>>54149245
an int[] is an object
>>
>>54149280
Please no bully.
>>
File: 1460873180472.jpg (109 KB, 672x474) Image search: [Google]
1460873180472.jpg
109 KB, 672x474
>>54147165
thats portuguese brah
probably a huezillian
>>
>>54149288
anon why are you repeating so much code
>>
>>54149245

> if ((i) < 3)
>>
>>54146532
All memes aside I think it's fine.
>>
>>54149340
Like I said, I'm a beginner, I don't really know what the fuck I'm doing. I know it looks like trash, but the logic in my head says it should just werk
>>
>>54149340
how to programmatically write different variables?
>>
>>54149354
> if ((i) <3)
>>
>>54149354
what's wrong ?
>>
>>54149375
>if ((i) <3||you)
>>
>>54149365
what are functions
??
>>
>>54149365
create a function to do this

if <die> == 3 or 5
return <die> - 1
else
return 0


then use some kind of container that your language has like a vector or a list or something and map it with that function (create an array of every application of that function to an element in the previous container)

F#:

let testDie a = if ((a = 3) || (a = 5)) then (a - 1) else 0

let dies = [| 3, 4, 6, 1, 3 |];

let results = dies |> Array.map testDie
>>
File: image.jpg (10 KB, 250x197) Image search: [Google]
image.jpg
10 KB, 250x197
>>54149375
>>54149386
cute
>>
>>54149378
unnecessary parentheses, just use:
 if (i < 3) 
>>
>>54149458
let if' a f b c = if (f c) then a else b

..

if' i (<3) u bby
>>
>>54149487
 func c(ute: Int) -> Bool { return true } 
>>
dead thread
>>
>>54149582
>what is a job
>>
>>54149591
I'm thinking they're high schoolers actually
>>
>>54149604
>>54149591
I'm at work now, for the record.

Lot of meetings today, so I'm less active.
>>
>>54149607
oh
im in class
>>
File: 91i328.jpg (142 KB, 740x740) Image search: [Google]
91i328.jpg
142 KB, 740x740
>>54149617
>OOP
>>
Your thoughts on best IDE/environment for working with C++?

I've used Visual Studio for C# for awhile now but fuck you Microsoft for making me take 2 fucking hours to run Windows Update before I'm even ALLOWED to update Visual Studio and install Visual C++ tools, which should already be there to fucking begin with.
>>
>>54149732
>fuck you Microsoft for making me take 2 fucking hours to run Windows Update
This only happens once. And it's not a good reason to hate an IDE. All that matters is how productive it makes you day to day. A once off 2 hour update is nothing.
>>
>>54149732
>what the fukc why do i hav to update from windows 98??????

Fucking retards, constantly delaying updates then fucking complaining
>>
>>54149732
Visual Studio.

I've never had this update issue you're talking about.

Are you running Community 2015?
>>
File: b64bb83300[1].png (9 KB, 453x634) Image search: [Google]
b64bb83300[1].png
9 KB, 453x634
>>54149926
>Are you running Community 2015?
Yes...
>>
Will two threads calling push_back/erase on a vector cause a segfault?
>>
>>54149632
kek
>>
>>54149732
vim + g++
>>
File: 1437394944041.jpg (9 KB, 250x219) Image search: [Google]
1437394944041.jpg
9 KB, 250x219
>No one else has solved and shared the same problem you had before
>Can't just copy someone's code.
>Actually have to write some code myself.

This sucks.
>>
I'm trying to get into coding. I want to make a flashcard app for learning Chinese for my own personal use, what should I use?

Currently going through the wiki now and I found bento.io Where should I start? Is this stuff fun?
>>
>>54150498
>being a codemonkey
>>
>>54150992
>get into coding
>coding
>flashcard app

just use anki you dip
>>
which is more efficient?

int exponentRecur (int base, int exp) {
if (exp == 0) /* base case */
return 1;
while (exp > 0) {
--exp;
return base * exponentRecur(base, exp);
}
}

int exponentIter (int base, int exp) {
int i, num;
if (exp == 0)
return 1;
num = base; /* if num = base then num is already at exponent 1 */
for (i = 1; i < exp; ++i) {
num *= base;
}
return num;
}
>>
>>54151090

Aww, I want to create cool stuff like you guys.

I have messed around with the code in Anki to change font and picture sizes, but that shits boring.
>>
    while (true) 
{
if (y == 0) break;
var remainder = x % y;
x = y; y = remainder;
}
>>
>>54151369
Iteration is generally better than recursion for that kind of shit
>>
>>54146532

What result does it give for 0.1 + 0.2?

(that is to say, are you using a BigDecimal class or something similar to store numbers internally, or are you doing the retarded thing where you use IEEE?)
>>
File: file.png (1 MB, 1280x768) Image search: [Google]
file.png
1 MB, 1280x768
this is an intro level python question, so someone here might actually be able to answer it.

How do I create a single python script that creates an object class, and a main class that creates such object? I don't want quick and dirty, I want to follow python conventions.

a Java equivalent would be:

public class Car {

private String make;
private String model;
private int year;

public Car(String make, String model, int year) {
this.make = make;
this.model = model;
this.year = year;
}

public static void main(String args[]) {
Car myCar = new Car("Mazda", "6", 2010);
//here I would do stuff with myCar
}
}
>>
File: ruby_is_a_brony.png (47 KB, 955x497) Image search: [Google]
ruby_is_a_brony.png
47 KB, 955x497
>>54151513
>>
>>54151449
You can't do anything like that if you're just starting

read a book
>>
>>54151496
Not necessarely tail recursion with optimizing compiler is as fast as iteration while usually being shorter and simple to write.
>>
>>54151369

The first one lacks a case for exp < 0, and your compiler should give you an error for not having a return statement for all possible values. Also, the while loop is strictly unnecessary, because you're making a return in it. You could best rewrite it like this:

int exponentRecur (int base, int exp) {
if (!exp) return 1;
else if (exp > 0) return base * exponentRecur(base, exp - 1);
else return 0; /* 1 / some_integer rounds down to 0 */
}


In any case, the compiler will usually optimize away tail recursion like this, so it's not really much of a problem of efficiency, so much as how easy it is for the function to be read and understood.
>>
>>54151513
That anon LITERALLY went over this like a month ago, based on suggestions of this basic float gotcha.
>>
>>54151683
>>54151709
>implying
return base * exponentRecur(base, exp);
is tail recursion
Take the poo to the loo.
>>
>>54151752

>like a month ago
I may not have been in DPT at the time. In any case, if that's the case, good on him.

>>54151597

Yes, and?
>>
>>54151787
Are the new MLP seasons good? I dropped it when that movie came out where they transform into humans
>>
>>54151807
>>>/mlp/
>>
File: 146102684552.jpg (31 KB, 268x364) Image search: [Google]
146102684552.jpg
31 KB, 268x364
>>
>>54151807
They're shit, sorry famalam.

We'll always have S1.
>>
>>54151780

This is what happens when you compile Anon's code unmodified:

PS C:\Users\Rubyist\Desktop> gcc -std=c11 -O2 -c recur.c
PS C:\Users\Rubyist\Desktop> objdump -M intel -d recur.o

recur.o: file format pe-x86-64


Disassembly of section .text:

0000000000000000 <exponentRecur>:
0: 83 fa 00 cmp edx,0x0
3: 74 17 je 1c <exponentRecur+0x1c>
5: 7e 13 jle 1a <exponentRecur+0x1a>
7: b8 01 00 00 00 mov eax,0x1
c: 0f 1f 40 00 nop DWORD PTR [rax+0x0]
10: 0f af c1 imul eax,ecx
13: 83 ea 01 sub edx,0x1
16: 75 f8 jne 10 <exponentRecur+0x10>
18: f3 c3 repz ret
1a: f3 c3 repz ret
1c: b8 01 00 00 00 mov eax,0x1
21: c3 ret


(14 nops omitted)

Show me where it grows the stack. Because it looks pretty tail recursive to me.
>>
>>54151867
should be
char * const s;
>>
src/main.c:238:2: warning: implicit declaration of function ‘glCreateShader’ [-Wimplicit-function-declaration]


I already included -lGL and #include <GL/gl.h>.
I don't understand why this is suddenly an issue now, it's worked countless times before.
>>
>>54151807

Some episodes are pretty decent, some are pretty shit. It's really something to judge for yourself.

And DPT isn't really for that kind of discussion.
>>
>>54151891
It's still not tail recursion. This is a separate optimization relying on the associativity of multiplication.
>>
>>54151992
And i didn't mean that was tail recursion i was talking in general terms.
>>
>>54151921
You need opengl extension wrangler.
>>
>>54149108

0 1 is U
1 1 is \s
>>
>>54152151
I have another program on this same machine that uses glsl shaders and I never needed any glew calls.

I already know for a fact that this machine supports shaders so why is it an issue now?
If you'd like, i can post the code that actually compiles.
>>
>>54151992

Anon, the canonical example of tail recursion is the factorial function, which is also multiplying the result of a recursive call.
>>
>>54152233
f(n - 1, m * n)
is tail recursion
n * f(n - 1)
is not
>>
File: ani.webm (1 MB, 854x480) Image search: [Google]
ani.webm
1 MB, 854x480
>>54147268
Sorry for the late (>.< '')

It's Black Bullet

https://en.wikipedia.org/wiki/Black_Bullet

>>54151891
There is no recursive call in that code (no calls nor jumps).


return base * exponentRecur(base, exp);


Is also not tail recursive (syntax-wise): the expression node of
exponentRecur(..)
is not a tail in the expressions tree.
>>
I need a wiki for my page. What are some good features it SHOULD have? Posting this here as well because dpt > wdg

I already made something really simple. A Page table in a postgresql db and some python logic which serves it's content. Some javascript with codemirror for previewing any edits you make.

So what do I add?

Right now, the basic url scheme is
www.site.com/wiki/MainPage <-- brings you to the page with the MainPage slug.
www.site.com/wiki/MainPage/edit <-- Brings you to the editor.
www.site.com/wiki/MainPage/history <-- Shows you the history of the page.
www.site.com/wiki/MainPage/talk <-- Brings you to a discussion thread concerning that page.

There are also REST bindings to delete/post/revert undo, but I'm thinking features.

More importantly, stuff like namespaces, tags and all that. Wikipedia among others implements namespaces with e.g
www.site.com/wiki/MyNameSpace:MainPage

which I think is ugly as FUCK. But I don't know any other way to do it as well. What do?

Basically, what do I need to add to my wiki that will make you want to edit it? I've already got a good editing setup which puts preview to the right, editor right.
Works like a charm in widescreen setups.

Gimme dat insight /dpt/
>>
>>54152151
>>54151921
nevermind, apparently C99 doesn't like implicit declarations so i replaced -Wall with -ansi instead.

It works great now!
>>
>find a font that loos really pretty
>eventually you notice this
Why would they do that? Lower case L's are supposed to be just a straight line or have a little bump in the bottom right and they are definitely not supposed to look like 1's.

Can't use this otherwise beautiful font now.
>>
>>54152643
droid sans mono?

I don't see the problem at all, they look very different side by side.
>>
Guys. Rust -- your opinion go.

Also other comparable general-purpose programming languages.
>>
>>54148889
java is literally one of the very fastest programming languages you silly memer
>>
>>54152759
it's shit, pointless and gay

C++ all the way
>>
>>54152780
No, the C++ ecosystem is broken and ugly. I want modules and a proper package manager.
>>
>>54152759
rust is trash that will be forgotten in 10 years
i don't confide in hipster web devs to write a systems programming language
>>
Opinions on kotlin? Seems less verbose than java, havent tried it yet.
>>
>>54152643
an l can look like that. Pic related is a spinoff of that
>>
>>54152802
>>54152780
So what's better?
>>
>>54152912
For systems programming, nothing beats C89.
>>
>>54152802
>10 years
Optimistic
>>
>>54152177
thank you ... :/
>>
>>54152838
it's SHIT and java being "verbose" is a fucking retarded shitter meme
>>
>>54146482

Effectively written 800 lines of c++ just today and am still going. halp
>>
>>54153009
>java being "verbose" is a fucking retarded shitter meme
Java IS verbose.

That's not necessarily a bad thing, though.

It just objectively is verbose compared to many other languages.

I personally prefer explicit verbosity because it leaves less margin for error.
>>
>>54153009
>it's SHIT
how so ?

>java being "verbose" is a fucking retarded shitter meme
it's not a meme, one example: setters and getters
>>
>>54153079
language verbosity is a meme cooked up by enterprise-y types who don't aren't programmers and will never have to type out their camelcased AbstractEveryFlavorBeanFactoryFactoryBean shit thousands of times a day.
>>
>>54153105
>this whole post
lol
>>
for my java class's final assignment i made a 20 line imperative algorithm instead of doing the thirty class OOP the assignment suggested, got it back and got 100%. feels good to be a gangster
>>
>>54153105
>who don't aren't programmers
opinion_discarded.jpg
>>
>>54153070
just start writing in assembly and verilog already
>>
>>54153080
kill yourself

getters and setters is what you use in any sensible program regardless of the language

but you wouldn't know since you're a clearly a script kid shitter
>>
>>54153131
Unfortunately you're using java so nobody wins
>>
>>54153163
It's for a final project that I had a month to do. Good thing I'm fucking legend at C++.
>>
>>54153178
Can you elaborate why u think its shit?
>>
>>54153202
what project is it mr legend?
>>
File: argument-typo.jpg (32 KB, 735x541) Image search: [Google]
argument-typo.jpg
32 KB, 735x541
>>54153158
Not that I agree with the person you're responding to, but pic related.
>>
>>54153229
count from 1 to 100, and if the number's divisible by 3, print fizz. if its divisible by 5, print buzz. if it's divisible by both, print fizzbuzz. the last part is what threw me for a loop
>>
>>54153178
are you retarded or something ? i am referring to the verbosity of getters and setters in java.

korlin has properties https://kotlinlang.org/docs/reference/properties.html
>>
>>54153253
nice meme mr autist
>>
>>54153286
what the meme did you just meme to me, you little memester?
>>
Could you guys post faster, please ? i want to make a new thread.
>>
>>54153229
I'm actually probably shit at it but I can program fast, whatever. I had to make a shit-tier interpreted language with a parse tree and basic functionality etc.
>>
File: vomit.jpg (55 KB, 312x312) Image search: [Google]
vomit.jpg
55 KB, 312x312
>>54153263
>korlin has properties
may as well use C# if you want that shit
>>
>>54153316
just make the new thread early bro, no one will care. proud of you
>>
>Kotlin is a programming language made by JetBrains
literally yet another cash cow and they're literally shilling jetbrains products in /dpt/
>>
>>54153326
yeah, u totally right, properties are more verbose than plain getters/setters.
>>
>>54153353
For what it's worth, JetBrains makes good shit.
>>
>>54153353
Do you have to pay to use it? kek
>>
whats the hate with oracle?
>>
So what programming languages you fucking fags?
>>
>>54153355
properties are straight up SHIT for fuck's sake

and getFoo() vs foo is 4 characters more OH WOW and you have flexibility like getFoo(bar) and readability (without properties you know you're not mutating state by simply accessing foo.fuckingBar)
>>
Working on the GNU Turd kernel
>>
>>54153386
what are you asking
>>
>>54153368
They make okay shit. It looks nice but it all too often feels like it's held together with a few rubber bands in the backend.
>>
>>54153390
but we are talking about verbosity, lel.
>>
>>54153402
Good compiled general-purpose programming language? Which one. C/C++ is disqualified -- I don't want to deal with the horrid ecosystem. You people seem to think Go and Rust are memes, so what's left?
>>
>>54153319
nice parse trees are cool

my last project in c++ was to create a B-tree which i was most def shit at implementing, but now I'm working on a hash table spell checker.
>>
>>54153393
nice, how'd you start working on it? what are you doing? are you aware your work is for a lost cause?
>>
>>54153410
var shittyProperty = foo.bar;


vs.

int sensibleVar = foo.getBar();


OH FUCKING WOW
>>
>>54153412
Crystal

http://crystal-lang.org/
>>
>>54153412
Haskell
>>
>>54153393
Are you apart of the kernel developers cuck maillist?
>>
>>54153368
ok shill

>>54153381
there is no sensible reason to use a fucking unpopular redundant hipster lang like that and they make money off of it indirectly fucking retard
>>
>>54153433
No functional programming, I want to be productive not pure.

>>54153432
I don't want to be programming Ruby, and if I chose Crystal I might as well go with Nim.
>>
>>54153421
>using mutable variables
It's not the 90s any more kiddo
>>
>>54153412
If you consider Java to be compiled, it's okay.
If you don't care about employability, use a meme language. Go is actually bad, though. I don't know about Rust but it looks gross, but people like it.

If you care about employability though, you're going to have to deal with 'the horrid ecosystem.'
C isn't half bad, C++ is half bad, Java is okay but you'll have to deal with pajeet
>>
>>54153412
x#
>>
>>54153421
but what the definition ?
>>
>>54153447
language-enforced purity helps you be more productive
>>
File: 9crgUfF.png (65 KB, 1201x696) Image search: [Google]
9crgUfF.png
65 KB, 1201x696
>>
>>54148993
You're still a webfag though, so please leave /dpt/, where the real programmers converse.

>>>/g/wdg
>>
>>54153458
int getFoo() {
// any custom logic
return foo;
}


SO FUCKING VERBOSE I CAN'T TAKE IT ANY MORE I'M GONNA SHOVE A VAGINA UP MY ASS AND KILL MYSELF
>>
>>54153447
>I chose Crystal I might as well go with Nim.
Why ? They are far apart.
Thread replies: 255
Thread images: 36

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.