[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: 33
File: K&R himegoto waifux2.png (1 MB, 1000x1400) Image search: [Google]
K&R himegoto waifux2.png
1 MB, 1000x1400
Return of the hime edition!
old thread: >>53489379

What are you working on, /g/?
>>
>>53497069
First for D
>>
>>53497060
C.
>>
linked lists are slow
>>
>>53497108
But they're easy to write and much less effort than making your own dynamic arrays like vectors.
>>
How do i end the program?
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter\t'p' to create a polygon"
+ "\n\t'q' to create a quadrilateral"
+ "\n\t'r' to create a rectangle"
+ "\n\t's' to create a square"
+ "\n\t't' to create a triangle"
+ "\n\t or any other character to quit.");
char userIn1 = scan.findInLine(".").charAt(0);

if(userIn1=='p'){
System.out.println("How many sides?");

}else if(userIn1=='q'){

}else if(userIn1=='r'){

}else if(userIn1=='s'){

}else if(userIn1=='t'){

}else
//WHAT NOW
}

>>
>>53497144
return 0;
>>
>>53497183
that doesnt work, im doing java
>>
>>53497183
void main bruh

System.exit(0);
>>
>>53497144
System.exit(0)
>>
File: rainbow.jpg (426 KB, 800x598) Image search: [Google]
rainbow.jpg
426 KB, 800x598
>>53497063
>>
>>53497199
>>53497200
What a worthless language.
>>
>>53497226
>literally the most used programming language in the entire world
>>
>>53497069
https://www.youtube.com/playlist?list=PL78B1DB5912371F14
>>
>>53497240
Muhammad is the most common name in the entire world.
>>
File: 011737114 .jpg (580 KB, 1000x986) Image search: [Google]
011737114 .jpg
580 KB, 1000x986
Anyone want to try their hand at this?

Draw an object graph for the objects created in the main method.

class Foo {
public Foo foo;
public Bar bar1;
public Bar bar2;
public Foo(Foo pFoo, Bar pBar1, Bar pBar2) {
this.foo = pFoo;
this.bar1 = pBar1;
this.bar2 = pBar2;
}
}

class Bar {
public Foo foo;
public String name;
public Bar(Foo foo, String name) {
this.foo = foo;
this.name = name;
}
}

class Main {
static public void main(String[] args) {
String evestr = "Eve";
Bar alice = new Bar(null, "Alice");
Bar bob = new Bar(null, "Bob");
Foo foo1 = new Foo(null, alice, bob);
Bar eve = new Bar(foo1, evestr);
Foo foo2 = new Foo(foo1, bob, eve);
Bar eve2 = new Bar(null, evestr);
}
}


Pretty sure my solution is wrong.
>>
File: 1457662511527.jpg (29 KB, 400x394) Image search: [Google]
1457662511527.jpg
29 KB, 400x394
>>53497144
while(1);
>>
>>53497144
wait for the GC to collect your code
>>53497261
>2.3 MB hello world
>smallish
>>
>>53497315
>GC
who?
>>
>>53497337
https://en.wikipedia.org/wiki/Garbage_collection_%28computer_science%29
>>
>>53497337
garbage (language) collector
>>
>>53497315
>wait for the GC to collect your code
kek
>>
File: output3.webm (2 MB, 640x480) Image search: [Google]
output3.webm
2 MB, 640x480
Rate my cube!
    glBegin(GL_QUADS);
/* front */
glColor3f(1.0, 0.0, 0.0);
glVertex3f(-25.0, 25.0, 25.0);
glVertex3f(-25.0, -25.0, 25.0);
glVertex3f(25.0, -25.0, 25.0);
glVertex3f(25.0, 25.0, 25.0);
/* left */
glColor3f(0.0, 1.0, 0.0);
glVertex3f(-25.0, 25.0, 25.0);
glVertex3f(-25.0, -25.0, 25.0);
glVertex3f(-25.0, -25.0, -25.0);
glVertex3f(-25.0, 25.0, -25.0);
/* right */
glColor3f(0.0, 0.0, 1.0);
glVertex3f(25.0, 25.0, 25.0);
glVertex3f(25.0, -25.0, 25.0);
glVertex3f(25.0, -25.0, -25.0);
glVertex3f(25.0, 25.0, -25.0);
/* bottom */
glColor3f(1.0, 1.0, 0.0);
glVertex3f(-25.0, -25.0, 25.0);
glVertex3f(25.0, -25.0, 25.0);
glVertex3f(25.0, -25.0, -25.0);
glVertex3f(-25.0, -25.0, -25.0);
/* top */
glColor3f(0.0, 1.0, 1.0);
glVertex3f(-25.0, 25.0, 25.0);
glVertex3f(25.0, 25.0, 25.0);
glVertex3f(25.0, 25.0, -25.0);
glVertex3f(-25.0, 25.0, -25.0);
/* back */
glColor3f(1.0, 0.0, 1.0);
glVertex3f(-25.0, 25.0, -25.0);
glVertex3f(-25.0, -25.0, -25.0);
glVertex3f(25.0, -25.0, -25.0);
glVertex3f(25.0, 25.0, -25.0);
glEnd();
>>
it's a cube alright
>>
File: Capture.png (19 KB, 529x446) Image search: [Google]
Capture.png
19 KB, 529x446
Why does it keep showing zero? I want it to go " side 1...side 2...side 3...
>>
>>53497570
your for loop is fucked
                                                                                                                                                                                                                                                                                                                                                                                                                                   or the GC hasn't kicked in yet
>>
>>53497570
You're appending x but not incrementing it
>>
>>53497220
>The C code cgo compiles seems inaccessible beyond a location in memory. So any C struct I want to look at leaves me with an address.
Can you explain this more? Is the memory segmented? Is the address the address of the struct? If so, there is no reason why you can't access them.
>>
>>53497570
Do a
 for (int i = 0; i < userIn2; i++)
instead.
>>
>>53497617
>>53497619
>>53497672

im not really used to enhanced for but how do you add x up 1 without actually adding it

for(int x = 0; x<userIn2; x++){
System.out.println("Enter the length of side "+x);
sides[x]=scan.nextInt();
>>
>>53497570
i'm not a java guy but that looks like an iterator, in which case x is always just the current value of sides at your iteration. Use a regular for loop, something like:
for(int x = 0; x < userIn2; x++)


The for loop you have written can be read as "for each value x in the array sides, do the following". All the values will be 0 by default since you haven't set them.
>>
>>53497570
There are a few things in that code that make no sense. There is no input validation. Your for loop is incorrect - you are iterating through sides, which is an integer array. You need to loop from x = 1 to x = userIn2, the number of sides. You should also use a switch...case statement in there, and you may want to consider getting user input in a different function.

Please post all relevant code.
>>
I am trying to sort a set of divs that have values from an array of objects file datafile.js

           <script id="data-template" type="text/html">
<div class="box">

<h4> <%= name %> <%= id %> </h4>

</div>
</script>

<div id="wrap"> </div>



so far I have

 
<script type='text/javascript'>
$(window).load(function(){
$('.Sorting').click(function() {
var $wrapper = $('#wrap');

$wrapper.find('.box').sort(function (a, b) {
return +a.getAttribute('#datafile','id') - +b.getAttribute('#datafile','id');
})
.appendTo( $wrapper );
});
});

</script>


what I am doing wrong here? the function just moves the order of divs randomly now
>>
>>53497832
please divert course to web shits general

>>53497570
it's all kinds of fucked
>>
Implementing functors in Java.
interface Functor<T extends Functor<?, ?>, A>  { 

public <B> T fmap(Function<A,B> f);

}

public class FunctorTest {

public static void main(String[] args) {
List<Integer> start = new ArrayList();
start.add(1);
start.add(2);
start.add(3);

ListFunctor<Integer> a = new ListFunctor(start);
ListFunctor<String> out = a.fmap(x -> x * 2).fmap(String::valueOf).fmap(x -> x + " kek");
System.out.println(b.val); // [2 kek, 4 kek, 6 kek]
}

}

class ListFunctor<A> implements Functor<ListFunctor<?>, A > {

public List<A> val;

public ListFunctor(List<A> input) {
this.val = input;
}

public <B> ListFunctor<B> fmap(Function<A, B> f) {
List<B> a = val.stream().map(f).collect(Collectors.toList());
return new ListFunctor(a);
}

}
>>
>>53497716
>>53497847
my code is shit but that is why i have come here.
>>
File: 1454896650817.jpg (550 KB, 857x1200) Image search: [Google]
1454896650817.jpg
550 KB, 857x1200
/gee/ blease help.
So here is my current situation:
>arduino project
>arduino grabs data and sends all out serial port
>raspberry acts as 'server'
>have nodejs frontend
>nodejs does the handling of the serial connection, too
>checks data, dumps 'good' data to database and refreshes webinterface if necessary (websockets)

Since you hear always about web front and backend development I guess this is a bad solution for me, right?
So if I would write a handler with a different language which only processes the serial data and dumps it to a database, then how would my frontend would get noticed and send data out the websockets?

yes, I am a web noob.,
>>
>>53497878
/wdg/

Shit code is only okay if it's in an actual language
>>
>>53497894
man you uninspire new coders like me starting out with java and no other option
>>
>>53497914
Java is a language

A shitty one, but still a language
>>
>>53497926
Java is good as starting language imo.
Pretty easy to understand logical concepts and shit. No in depth knowledge needed.
I started with java too and now I am programming mostly in C and for scripting some python shit.
>>
>>53497893
>>nodejs does the handling of the serial connection, too
in what universe is this a good idea
>>
>>53497963
It is obviously not, but I thought it might be cool to open and close the serial port through the webinterface, which was pretty easy that way.
But I acctually do not need that.
>>
>>53497949
Never touched java until I got into android development.

It's a horrible language and the shitty convoluted android API doesn't help one bit.

I started and still am in C++ and I'm going partly C to try to into embedded systems
>>
>>53497993
What is horrible about Java?
>>
>>53497997
it Sucks
>>
Hey guys, pretty new to C++ (I'm doing Python in a class and C++ interests the fuck out of me. I think I'm handling learning both languages fine). I'm trying to make a simple program which calculates an approximation of pi using the formula
pi = 1/2 + 1/4 + 1/8 + 1/16...

If that's not actually a formula to calculate pi, i no longer care, because I just want to get this code right.

This is my method
void calcPi() {
int accuracy;
double total = 0;
int j = 2;
cout << "How accurate do you want your approximation (whole numbers only)? ";
cin >> accuracy;
for (int i = 0; i <= accuracy; i++) {
total += (1 / j);
j *= 2;
cout << total << endl;
}
cout << total;
}


This just ends up returning 0 every time the loop runs. I'm not really sure what I'm doing wrong here. At first I thought it was because I made total an int initially, rather than a double, but that hasn't had any effect.
>>
>>53497997
Just a personal distaste. Overly verbose, never really liked the structure, no pass by reference, tries to be low level but isn't.
>>
>>53498055
Change int j = 2; to float j = 2.0f;
>>
>>53497120
Just use contiguous arrays fuckface.
>>
>>53498067
>tries to be low level
no?
>>
>>53498055
>>53498081
or better yet keep it in because you do *= 2 and change
>total += (1 / j);

to
>total += (1 / (j * 1.f));
>>
>>53498081
".0f" isn't necessary
>>
>>53497447
>glBegin
It's shit.
>>
>>53498067
Just because you don't like it, doesn't mean the language is objectively horrible.
>>
>>53498126
Right. It would be the opposite of objective... uh... subjective.
>>
>>53498105
>>53498099
>>53498081
Thanks heaps. Why does it need to be a float if it's only ever going to be a whole number?
>>
>>53498242
integer division
>>
>>53498242
because you're doing an integer division so 1 / 2 will yield 0 instead of 0.5 because it gets truncated
>>
>>53498261
>>53498257
Okay, that makes sense. Thank you very much.
>>
Good read, https://techblog.badoo.com/blog/2016/03/14/how-badoo-saved-one-million-dollars-switching-to-php7/
>>
>>53498495
>>>/g/wdg/
>>
test
>>
>roller coaster tycoon 2 was written almost entirely in x86 assembly by one guy
I need to step up my fucking game jesus christ
>>
>>53497447
Use a vertex list/buffer or what it's called nowadays.
>>
>>53498654
>not writing portable software
it's 2016, get with the times fampai
>>
>>53498654
Chris is a sperg savant don't worry

He's my hero tho
>>
public static void main(String[] args) {

List<Integer> list=new ArrayList<Integer>();

for(int i=0;i<1000;i++)
list.add((int)(Math.random()*6)+1);

System.out.println(numberofSixes(list));
}

public static int numberofSixes(List l){
int a=0;
for(int i=0;i<l.size();i++)
if(l.get(i).equals(6))
a++;
return a;
}

Could you help me change this program so that instead of a list it uses a vector?
And also make it so that it counts all values less than three.
>>
>>53498740
Do your own homework
>>
>>53498874
That's what I'm doing.
>>
>>53498740
You people are truly worthless. Why not help me? I know that you can fix my problem.
>>
>>53498926
>>53499066
jesus christ
>>
>>53498740
Change List to ArrayList.
>>
>>53498067

>no pass by reference
do you mean by value? everything except primitives pass by reference

>tries to be low level
really? i would argue rather that it tries to be too high-level

there's no shortage of reasons to criticize java, but at least have your facts straight when you do
>>
File: Animated Gif-80.gif (450 KB, 320x249) Image search: [Google]
Animated Gif-80.gif
450 KB, 320x249
Totally new to python so noob question here, just trying to get this program to check if 5 minutes of time has passed and then print the time. Wtf am I doing wrong:
import time
current = time.time()
future = (current + 350)

while True:
current != future
if future = time.time()
print time.strftime("%H:%m")


I keep getting a syntax error on the "if" statement. Since time.time() is floating point and is assigned to the variable "current" why can I not compare the variables "current" and "future". I just get "syntax error" and it points to the equal sign.
>>
>>53499826
shit its supposed to be
while True:
current != future
if current = future
print time.strftime("%H:%m")
>>
What's the best way to distribute code across devices to test client-server software?
>>
>>53499861
sockets are sockets, just run it on the same device m8
unless you're testing how fault tolerant your protocol is, in which case you're better off using automated tests
>>
>>53497287
>not using standardized flowchart formatting
>still expecting us to be able to read this
>>
Which do you use?
void main() {
return 0;
}

OR
void main()
{
return 0;
}
>>
>>53499826
from time import time, strftime

current = int(time())
future = current + 300

while True:
current = int(time())
if current >= future:
future = current + 300
print(strftime('%H:%m'))
>>
>>53500107
I just realised I made that void. This is why I'll never get anywhere.
>>
>>53500140
Some C-like languages allow for void main functions and simply default to exit code equal to 0. For instance this is completely valid D:
void main(string args[])
{
}
>>
>>53500107
int main(int argc, char **argv)
{
return 0;
}

(imagine I had used a tab for indentation)
>>
>>53499826
>>53499836
= is for assignment, not comparison
and the block after the if needs to be indented
Why are you doing "current != future"?
Just use time.sleep(350)
>>
>>53500172
I'm fairly certain that a tab is usually equivalent to 4 spaces.
>>
>>53500180
You're fairly wrong then
>>
>>53500168
I've never done Java, C# or D, and I'm new to C++. What does string args[] actually mean?
>>
>>53500207
In most IDEs a tab is worth 4 spaces.
>>
>>53500215
It's a string array named args. It's get passed the command line arguments to it.
>>
>>53500180
>>53500224
The point of tabs is that you can set any width up to preference.
>>
>>53500224
>IDE
>>
>>53500236
I never actually considered that. From my experience I've always had the default be 4.
>>
int main (int argc, char **argv) {
(void) argc;
(void) argv;
return 0;
}
>>
http://lmgtfy.com/?q=how+many+spaces+is+a+tab
>>
>>53498055

First of all, that infinite series converges to 1, not Pi. If you wanted to calculate Pi using an infinite series, use 4 - (4/3) + (4/5) - (4/7) + (4/9) ...

It's in essence the sum from n=0 to infinity of ( 4 * (-1)^n ) / (2n + 1).

But there's an easier way to approximate Pi that any programmer can do -- the Monte Carlo method. Imagine you have a square of side length n. Inscribed inside that square is a circle of diameter n. Now say we are to throw an infinite number of darts randomly at that square. The ratio of darts that land inside the circle to the darts that land anywhere on the square (inside or outside the circle) is 1/4 of Pi. How can we tell? Well, the area of the square is n^2, and the area of the circle is Pi * (0.5n)^2, or 0.25 * n^2 * pi. So the area of the inscribed circle is Pi / 4 times the area of the square.

Here's an example in Ruby:
def monte_carlo_pi iters
inside = 0.0
iters.times do
x = rand
y = rand
inside += 1.0 if (x*x) + (y*y) < 1.0
end
4 * inside / iters
end
>>
>>53500109
Christ, thanks anon.
I'm mainly thankful cause I can now see the correct syntax and see wtf I was doing wrong. Appreciate it.
>>
>>53500422
Yeah, I had kinda deduced after like 3 seconds of properly looking at the formula that I was being retarded for thinking that would give me pi (Me and my friend were talking about maths and he talked about one of his old teachers who explained how pi was calculated and he threw that formula at me and, without thinking about it too hard, went and made a program to do that).

I've heard about that method of calculation before, and I'll save your code to try and iterate into C++ when I learn how to do a few more things. Haven't gotten into graphing at all with any language before, but I can remember how to do it from high school maths, so I'll give it a go hopefully soon. </blog>
>>
>>53500175
Honestly I knew there was a premade function undoubtedly somewhere in the Python library that could do this. I just wanted to practice programming python and get my brain to wrap around thinking in a programmer sort of way. So I thought I'd attempt to program this for the sole purpose of brain training, I guess you could call it.
>>
File: monte-carlo-pi.png (19 KB, 446x502) Image search: [Google]
monte-carlo-pi.png
19 KB, 446x502
>>53500507

You don't need to graph anything, mate. Here's the equivalent in fucking PowerShell. Small line of code count, starts to approximate a couple of significant digits as you ramp up the number of iterations.

Now a real challenge would be to get a good parallel Pi crunching.
>>
File: hitmanrl.gif (22 KB, 589x233) Image search: [Google]
hitmanrl.gif
22 KB, 589x233
Do you havean idea of how this is made so I can get to writing?
>>
>>53500546
Why don't I understand this? I feel stupid every time something involves maths.
>>
>>53500900
Haha, I'm actually handwriting notes to help myself understand how this is all calculated. Feels like I'm in school, but I'm somehow enjoying this.
>>
>>53497069
Stop this programming trap meme.
>>
File: bb1.jpg (81 KB, 1280x720) Image search: [Google]
bb1.jpg
81 KB, 1280x720
learning c++, what is a good library for for a beginner to make guis?
>>
>>53501088
Stop this stop this programming trap meme meme.
>>
>>53500900
Inside holds the number of points that inside the circle. The for loop does $iters iterations. For every iteration, x and y are random numbers between 0 and 1. x^2 + y^2 calculates the point's distance to the origin (ie x = 0 and y = 0). If that distance is less than 1, then the point is inside a circle with radius 1. A circle with radius 1 occupies an area of pi / 4 in the region with x = 0 to x = 1 and y = 0 to y = 1. Hence, if $iters is large enough, pi can be calculated as 4 * fraction of points that are in the circle.
>>
>>53501137
Qt. Haven't used it but I've seen it recommended.
>>
>>53501137
Qt, it's not specifically for beginners, and I would strongly advise against using it until you get a bit comfortable with C++, but it's the best UI framework out there.
>>
>>53501160
cheers I’ll take a look
>>
>>53501137
ncurses
>>
>>53501336
Not cross platform.
>>
>>53500422
Is there any mathematical reason that the area of a circle divided by the area square equals exactly a quarter of pi?
>>
>>53501467
If the square has side length a, then the square has area a^2.

The circle has area pi r^2 = pi(a/2)^2 = pi*a^2/4

Circle divided by square is then pi/4.
>>
>>53501534
Your mom divided by square is pie/whore.
>>
So, gee, have you safely getchar() today?
>>
>>53501673
You're a really shitty troll.
It's either averaging ints, getchar or some other stupid shit I can't remember. Go get a job.
>>
Would it be frowned upon to use car and cdr instead of first and rest in Scheme? I'm just more used to them from using CL.
>>
Say I wanted to make a game. But I didnt want to use unity or cryengine. How exactly do I go about this. As in how would I make a gui to even start with. Ive been considering looking up how to make a model viewer first and going from there but I have a few questions first.
Is what I want feasible. Ive only made cli and I can deal with threads, but how exactly are graphics threads dealt with. If its in any way related to the graphics being used or something should I just go for a game engine because I dont really want to make my game specific to one os.
Is it possible that I can just make it using opengl (whatever that means) and I wont have to worry about graphics cards and os.
>>
>>53502181
>Is it possible that I can just make it using opengl (whatever that means) and I wont have to worry about graphics cards and os.
That's how you do it, with DX or OGL but you will still have to worry about graphic cards and OS because different card support different versions of OGL (so some features might not be available) and the driver support varies from platform to platform and from vendor to vendor.
>>
>>53502181
Unity is compatible with basically every single OS.

Unless you're an autistic savant, don't bother rolling your own engine unless you literally can't develop your idea with another engine.
>>
>>53502181
make a graphical abstraction layer in your code
make concrete implementations of said layer using DX or OGL and switch based on OS during compilation/runtime
>>
>>53502278
I guess I should have been more specific. I dont want to have to program for specific graphics cards or need to look at driver sdks or whatever. So really I just dont want to look beyond the compatibility list.
>>53502372
Why are you against having your own engine?
>>
Is college worth it or should I just learn how to program and move up the ladder by myself?

Degree is definitely attractive but fuck the courses are lame as fuck and a lot of it is pointless shit taught in a very inefficient way. However I've left school once before and am embarrassed of leaving again.

Just stick to it? What do you guys think?
>>
>>53502405
Why reinvent the wheel? It took hundreds of programmers years to write and debug those engines, and by the time you do it all from scratch yourself you may not be interested in your game anymore.
>>
>>53502405
>Why are you against having your own engine?
There's nothing inherently wrong with it if you've got literal years of free time and plenty of knowledge of math.

It's insane to recommend the average person to write their own game engine when there are robust, cross-platform options available.
>>
>>53502413
Job experience is king, but you'll limit your options and hit paywalls at many companies with no degree.

I'd say stick it out and get it, but I don't know you or your life situation.
>>
>>53502413
learn from college to get a job, learn from 80s MIT books to be a good programmer
>>
>>53499208
Java is mid-level, technically. Also, Java is pass-by-value only, http://stackoverflow.com/questions/40480/is-java-pass-by-reference-or-pass-by-value.
>>
>>53502399
Hmm I think I know what you are talking about. But wouldnt this dramatically slow down your code. Itd probably make more since once I started looking into how gui's work. I got disheartened when I was first looking at windows api stuff though.
>>53502434
Well I had nothing better to do in college so I have math/physics/cs majors.
But yeah I could see it being a problem that by the time I actually make the engine I dont care anymore like>>53502432 said.
>>
>>53500845
>>/vg/agdg/
>>
>>53502405
Yes, you can just do openGL once and if their graphics card isn't ancient as fuck, it will probably run.

In real advice, if you don't like unity or unreal or whatever, you should probably get a library that handles all the graphical backend for you. The rest of the stuff that a game engine provides is easy enough to setup yourself from there. I'm not sure what options are available for 3d stuff but I'm sure there is something out there.
>>
Is C# the best programming language for Windows apps, /dpt/?
>>
>>53502476
>But wouldnt this dramatically slow down your code.
not really, we're talking a couple of virtual method calls per frame here
thats the least of your worries right now though
>>
>>53501804
>I can't do the challenge
you don't belong here, m80
>>
File: cvafzu.webm (300 KB, 890x352) Image search: [Google]
cvafzu.webm
300 KB, 890x352
Guys
help
It started doing this for no reason suddenly
How do I fix
I'm using intellij ultimate
>>
Racket or CL for developing software with Lisp? Racket is definitely updated more often...
>>
Why is it the convention to do this:

if(true) {

}


Instead of this:
if(true)
{

}


In JavaScript? The first way felt comfy at first, but I'm always forgetting a nipple bracket with it.

The second way is more practical.
>>
for loops or while loops in java?
>>
>>53502675
>nipple bracket
It's called a brace your Mongol.
>>
>>53502675
former for single line code
>>
File: 2016-03-15_09-20-25.webm (30 KB, 200x78) Image search: [Google]
2016-03-15_09-20-25.webm
30 KB, 200x78
>>53502581
What's the issue?
>>
>>53502717
Foreach
>>
>>53502675
t's because JavaScript inserts semi-colons if you "forget" them.

return
{
key: "value"
};

returns nothing and then has an object literal statement that does nothing.

return {
key: "value"
};

returns the object literal.
>>
>>53502581
It's supposed to do that pajeet. It's called autocomplete.
>>
>>53502741
Pressing enter while between brackets does not insert two new lines and does not indent with tabulation.
For example I get
while(true)
{
}

Instead of
while(true)
{

}
>>
>>53502752
Makes sense, but it seems a bit autistic to set a convention because of a few small cases.
>>
>>53502947
Yeah use what you want. Just be careful if you ever want to return an object literal for some reason. I'm pretty sure that this is the only situation where it matters as well.
>>
>>53501804
>stupid shit I can't remember
are you even a real programmer?
>>
>>53502788
Please respond ;_;
>>
>>53502947
>autistic to set a convention because of a few small cases
>as opposed to remembering the different syntax for special cases
your autism evaluator might be broken
>>
>>53503031
He clearly isn't. Sorry if I can't retain all the inane memes and drivel /dpt/ comes up with on a daily basis; I have a job and responsibilities.
>>
Made some functions for working with continued fractions.

let rec dtof a b =
[
if b <> 0I then
yield a / b
yield! dtof b (a % b)
]

let ftod fractions =
let rec innerf aux =
function
|[] -> aux |> fun (a, b) -> (b, a)
|e::e' ->
let (a, b) = aux
let a' = e * b + a
innerf (b, a') e'
(List.rev fractions) |> innerf (0I, 1I)

let fibonacci n = List.replicate n 1I |> ftod |> snd


It's faster than I would expected it to be.
>>
>>53503099
>inane memes
codewords for "advanced topics above my understanding"?
>>
>>53503044
look through the prefs idk
>>
what about EOF again?
>>
>>53503260
anons don't know it's not enough to just check for EOF
>>
holy shit I fucking hate math kill me
>>
I have checked the gentoomen library and also had a good google. Are there any resources on BCPL around? I interviewed for a job that seemed pretty positive, they teach on the job but would be nice to get a head start.
>>
Anyone have any C tips?
>>
>>53503342
always check feof() and ferror(); don't try to average 2 ints
>>
>>53503129
Yeah?
What do I look for?
>>
File: htcvive.webm (2 MB, 1920x1080) Image search: [Google]
htcvive.webm
2 MB, 1920x1080
Ask your favorite programming literate anything (IAMA)

>>53503342
https://matt.sh/howto-c
subscribe to /r/C_Programming
>>
>>53503622
Kill yourself.
>please, no bully
Kill yourself.
>>
File: white_laser.jpg (370 KB, 800x598) Image search: [Google]
white_laser.jpg
370 KB, 800x598
>>53497623
yeah the address of a struct...well a C.struct. I have a field in a Go struct that contains a pointer to a pointer in Cgo, which itself points to a struct.
(dlv) print path
*struct github.com/andlabs/ui.Path {
p: *struct github.com/andlabs/ui._Ctype_struct_uiDrawPath {},
}
(dlv) print &path.p
(**struct github.com/andlabs/ui._Ctype_struct_uiDrawPath)(0xc820032010)
(dlv)



looking into C structs, the documentation states that:
>Go code may pass a Go pointer to C provided the Go memory to which it points does not contain any Go pointers. The C code must preserve this property: it must not store any Go pointers in Go memory, even temporarily. When passing a pointer to a field in a struct, the Go memory in question is the memory occupied by the field, not the entire struct.
>When passing a pointer to a field in a struct, the Go memory in question is the memory occupied by the field, not the entire struct.

so it seems I am boned
>>
>>53503622
Appreciate your frequent helpful contributions to /dpt/.
>>
ok here goes.
what other than the standard, boost and the Qt library do i have to know about when using C++.
those three almost cover everything.

also should i go unity or godot or gamemaker?
i am aware of godot being the only one that uses C++

>inb4 /vg/agdg/
I'm asking for your thoughts, not their's.
>>
>>53503840
Sdl also uses c++
>>
>>53503885
and ruby
>>
>>53497447
>Rate my cube!
Deprecated as fuck
>>
File: gAzPjVR.png (90 KB, 350x277) Image search: [Google]
gAzPjVR.png
90 KB, 350x277
>>53503901
When you know one, you know them all.
>>
File: 1345606553417.jpg (39 KB, 249x229) Image search: [Google]
1345606553417.jpg
39 KB, 249x229
Does anyone know a good intro to UML book? My software engineering prof is fucking useless and he assigned his own book because he's a narcissist or something

>Powerpoint
>Read from slide almost verbatim
>Underline literally everything in the same color as he goes
>"Any questions?"
>Next slide
>Repeat

Oh and the curry behind me is lapping this shit up, kek
>>
>>53503999
The curry that's going to take your job because he's actually paying attention? Fucking idiot. Drop out.
>>
>>53504023
I'm paying attention, it's just not doing shit for me. Everyone I've talked to is in the same situation. Prof sucks, book sucks

Either curry is already familiar with the material or he's found another source, which is what I'm looking for
>>
>>53504049
>curries
>either of that
Yeah, nah. I think he's just amazed how the world beyond his shitting street has advanced.
>>
>>53504071
STOP FUCKING MAKING FUN OF US
FUCK YOU
>>
I know little of python and C++ and I feel like I would like to learn some high level language. Is java good?
>>
>>53504119
Python and C++ are high level languages mate
>>
>>53504155
Compared to machine code, maybe.
>>
>>53504119
So you already know a little Python and C++? I'd just keep learning those for a bit until you really get them. Python is a good high level language to learn on, and C++ is a clusterfuck that and C are the closest you'll get to the machine without touching assembly
>>
>>53504172
Uhh
>>
>>53504181
but that and C*
>>
File: 1457879429825.jpg (166 KB, 600x600) Image search: [Google]
1457879429825.jpg
166 KB, 600x600
>>53504172
>>
>>53504192
>>53504203

P sure he meant C++ is high level compared to machine code, not Python
>>
File: 1457879933300.jpg (132 KB, 1584x891) Image search: [Google]
1457879933300.jpg
132 KB, 1584x891
>>53504222
Just say "I" instead of "He"

Still doesn't make ANY FUCKING SENSE
>>
>>53504222
Correct. Python is just a C interpreter, making it low level.
>>
File: 1457880094477.jpg (191 KB, 749x903) Image search: [Google]
1457880094477.jpg
191 KB, 749x903
>>53504240
>C
>Low level
>>
>>53502788
because you keep your cursor before the } rather than on the previous line after {
>>
>>53504239
pic m8
nice shitposting btw

>>53504240
wew lad
>>
>>53504260
Are you retarded? C is assembly with minimal abstraction. You probably think everything not assembly isn't low level, retard.
>>
File: 1457879552312.jpg (23 KB, 424x317) Image search: [Google]
1457879552312.jpg
23 KB, 424x317
>>53504279
>You probably think everything not assembly isn't low level
>>
>>53504279
stacks and heaps are a C abstraction, ASM only cares about registers
>>
>>53504279
>C is assembly
/g/ everyone!
>>
File: u7zfhUt.png (57 KB, 625x626) Image search: [Google]
u7zfhUt.png
57 KB, 625x626
>>53504279
quit now
>>
>>53504279
>Are you retarded? C is assembly with minimal abstraction.

hahahahahaha
>>
I think I will learn java

regards >>53504119
>>
>>53504305
you're loss
>>
>>53504293
there's no stack nor heap in C
>>
File: 1438771473501.jpg (12 KB, 251x242) Image search: [Google]
1438771473501.jpg
12 KB, 251x242
>>53504315
>there's no stack
>>
>>53504313
Why?
>>
File: shitbait.jpg (103 KB, 625x626) Image search: [Google]
shitbait.jpg
103 KB, 625x626
>>53504315
>>
>>53504328
>>53504338
>I haven't read the standard
you don't belong here, lads
>>
>>53504350
If there's no stack then where do the variables go???? My SSD??????
>>
File: 1366898176938.png (73 KB, 387x429) Image search: [Google]
1366898176938.png
73 KB, 387x429
Morning gents. I'm working on balancing a tree via rotations. Say I am checking to see if the tree is balanced. I'll be performing rotations about the root, the leftChild, and the rightChild. Here is the following algorithm:

void rotate_left(TreeNode * root)
{
TreeNode * x = root;
TreeNode * y;
y = x -> rightChild;
x -> rightChild = y-> leftChild;
if(y-> leftChild != NULL) {
y -> leftChild -> parent = x;
}
y -> parent = x -> parent;
if(x-> parent == NULL) {
root = y;
} else {
if(x == x -> parent -> leftChild) {
x->parent->leftChild = y;
} else {
x-> parent -> rightChild = y;
}
}
y -> leftChild = x;
x -> parent = y;
}


At the end of the function I call it from, I need to return the root, something declared globally and fed from another function.

Am I updating the root PROPERLY within this? I have the sneaking suspicion that I didn't implement this and I should restructure it a bit to return something rather than a void. I'm calling the rotate functions this way.

    if(rootBalance > 1) {
if(leftBalance < 0) {
rotate_left(root -> leftChild);
}
rotate_right(root);
} else if(rootBalance < -1) {
if(rightBalance > 0) {
rotate_right(root->rightChild);
}
rotate_left(root);
}
>>
>>53504359
C is not concerned with your SSD; go ahead and search the standard to see if it contains "SSD"; while at it, search for "stack" and "heap"
>>
>>53504389
You didn't answer the question.
>>
>>53504389
Then where do the variables go???
>>
>>53504389
I checked the standard. Fuck me, you're right. I suppose the stack and heap model are so common that we take them for granted

>>53504410
Up to the implementation?
>>
>Learn C first, then other languages will be easier to pick up

Is this a meme?
>>
>>53504404
>>53504410
why don't you want to read the standard? you prefer to stay dumb?
>>
>>53504421
no

all modern and relevant languages are C or C-based or at least heavily C-inspired.
>>
>>53504423
To be fair it was kind of a pain in the ass to find the actual document, the website is shit. I suppose I'll link it for other anons

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf
>>
>>53504419
>>53504423
It's not in the standard but you need a fucking stack or heap to run programs.
>>
>>53504441
Uh, hand-written assembly?
>>
>>53504423
Slick dodge kid
>>
>>53504441
>you need a fucking stack or heap
C doesn't impose such a requirement
>>53504461
stay dumb
>>
>>53504478
Some slick dodges here kid. Still haven't answered the question.
>>
C is a language with more undefined behavior than defined. It is also 110 years old.

It belongs on the trash heap.
>>
>>53504359
There's a separate variable alloc retard
>>
>>53504374
This is the most common mistake with pointers and data structures in C. (It's C, right?)
A complex data structure should never return any single element as the root to the caller. There must be a small layer of abstraction in between, in case of when the root changes. Your case is the textbook example.

Long story short, you need another struct called Tree that holds the pointer to root. Do not access the nodes directly.
>>
>>53504502
>110 years old
tfw 1990 was 50 years ago
feels old man
>>
File: sotd.jpg (67 KB, 576x720) Image search: [Google]
sotd.jpg
67 KB, 576x720
>>53504279
>C is assembly with minimal abstraction.
>>
>>53504490
it's answered in the standard, no point in repeating it for idiots that can't read
>>
>>53504502
>C is a language with more undefined behavior than defined.
which is why it's the perfect language for programming kernel.
>>
>>53503260

What about it? See >>53491567 and >>53492081
>>
File: g_414x655.png (288 KB, 414x655) Image search: [Google]
g_414x655.png
288 KB, 414x655
Motivate me /dpt/, why should I keep learning C++? I just can't motivate myself on doing my assignments. Why do you use it? I personally don't like it because it's not aesthetically beautiful. Take into account this piece of code:
#include <gtkmm.h>
int main(int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
Gtk::Window window;
Gtk::Main::run(window);
return 0;
}

The scope resolution operator in this code looks ugly as fuck.
>>
>>53504557
Just so we can close the case on this: You don't have an answer.
>>
>>53497183
it's a void you dip
>>
>>53503359
>always check feof() and ferror()
For what purpose?
>>
>>53504518
C++ actually but yeah I see what you are sayinf.

The kind of crippling problem is that I only have access to one structure, the tree itself with a global pointer to root. (thanks for efficient coding practices Computer Science courses!)

I see what you are talking about though so I'll see what I can do about it. Cheers anon
>>
>>53504518
>mutating things that others have access to at the time
>>
>>53503999
UML is a waste of resources. Seriously. The ratio of work invested to work got back is too big for it being useful.
>>
>>53504567
jesus christ, fucking tripfags are the cancer of /g/! this is why the board has gone to shit, you can't even have a good meme anymore
>>
>>53504678
Oh I know full well, but I have to learn it for my CS degree and even if I could bullshit the class I'd at least like to understand it
>>
>>53504439
> comittee draft

I never understood this shit honestly ffam. Is it just a retarded pre-digital policy to never disrupt whoever's monopoly on distributing the true and honest version? Is there any difference between the draft and the real standard? If not, what's the point?

I mean, if there is, that's just misleading and harmful for the public, no?
>>
>>53504593
just so we can close it: you're mentally ill
>>
>>53504589
Get a Macbook, buy a dildo, go to Starbucks and start writing Ruby then.
>>
>>53504682
>tripfag actually puts an end to the shitposting and general derailment
>people still fucking mad just because it wasn't an anonymous poster

You sound like the kind of person who gets mad when they receive a gift, because it makes you look bad for never doing anything nice for others yourself.
>>
>>53504694
It's too much like socialism. You know it don't work, never will, but always will have some professor selling it like it's the greatest idea since the wheel. It's kinda sad...
>>
What is your favourite programming language and why?
>>
>>53503622
How_To_Make_People_Bonk_They_Are_Head.webm
>>
I have a game thats in japanese, and I want to update its ui so that its menu, items, and skills will be in english. Whats the most effective way to do this?
>>
>>53504665
The abstract layer has to be there in order to prevent exactly that.
>>
>>53504695
ISO only exists because of the money people pay to get access to the finalised versions.

I don't even know of any universities who have open access to ISO standards via subscription or whatever.

It's about the only "fair" universal system since they fuck over everyone equally with their fixed prices.
>>
>>53504359
>>53504410
>>53504441
Here's some code
#include <stdlib.h>
unsigned math_shit(unsigned n)
{
unsigned s;
unsigned *h = malloc(sizeof *h);
*h = n >> 1;
*h *= 3;
s = n >> 2;
s *= 4;
n = s + *h;
free(h);
return n;
}

Which variable is on stack and which is on heap?
>>
>>53504755
Reverse engineer it and replace the strings with english.
It's going to be painful, on account that all your doujin japanese games use antiquated, largely undocumented windows-only frameworks.
>>
>>53504740
>mad when they receive a gift
actually I do get mad; gifts are the fucking worst!
>>
>>53504755
Do you have the source code?

No?

Well shit, looks like you're going to have to try to run a sniffer on the assets and replace the values. Might involve some hex translations.
>>
>>53504593
Ok look. I am not him, but you are starting to act fucking retarded.

The stack and the heap are not defined anywhere in the standard. I haven't read the standard, so I don't know how much it defines memory allocation if at all, but I at least know that there's no requirement to have a stack or a heap. The stack and heap are common solutions to the allocation problem. They're so common in-fact that they're basically synonymous with C. In reality though, nothing is stopping you from creating a fully compliant C implementation using a different model.

Why is this the case? Portability and performance. The C standard leaves a lot of implementation details undefined so that someone writing a compiler can make choices specific to their implementation. E.g. A microcontroller might have a completely different architecture than your average laptop, and compiling performant machine code requires that you work with the architecture.

I thought that the stack and heap were a given in C. Other anon told me (rather rudely, I'll admit) to search the standard for the terms. They weren't there. He's right. I shelved my pride and learned something. Don't be a goddamn idiot. Learn from others.
>>
#include <stdio.h>

int main()
{

//This program rounds off integer i to the next largest multiple of integer j*

int Next_multiple;

Next_multiple = (double) 10 + 3 - 10 % 3;

printf("The next largest multiple of 3 from 10 is %f", Next_multiple);

return 0;

}


Babby C learner here. I am trying to figure out how to convert a variable from type int to float or double. When I run this code, the %f I get is 0.00000 which I'm assuming isn't right.

When I replace %f with %i the code works fine but that's not the issue here, I'm just using this program as an example.

How can you convert variable types?
>>
>>53504836
Here's another really basic example

#include <stdio.h>

int main(void)
{
int boo;

boo = (double) 2;

printf("%f", boo);

return 0;
}


The result I get is 0.00000. what gives?
>>
>>53504889
boo is int.
2 is int.
2.0 is not.
>>
>>53504889
Ran that on ideone and got -0.852583. My theory is something about couble being 8-bytes and int being 4-bytes, but I'm not sure.
>>
>>53504713
I didn't ask 'which progayming language is best for me plz' I just wanted a valid opinion specifying why you like C++. It is one of the mandatory subjects I have to take, but as you can see, I don't like it.
>>
>>53504977
Because it's the most logical and versatile
>>
>>53498055
calcPi = lambda x: sum(1/n for n in range(2,x+1))
[/ccode]

God I love Python. It's so easy to do one liners
Thread replies: 255
Thread images: 33

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.