[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


Thread replies: 348
Thread images: 32

File: 1435541846284.jpg (1MB, 1920x1411px) Image search: [Google] [Yandex] [Bing]
1435541846284.jpg
1MB, 1920x1411px
Old thread: >>54440731

What are you working on, /g/?
>>
>>54449922
IDK
>>
>>54449922
I'm fucking you're mum as a gift to her
>>
Please do not use an anime image next time, thanks.
>>
>>54449922
Trying to prove that anime is real
>>
File: babachibababa.gif (2MB, 480x270px) Image search: [Google] [Yandex] [Bing]
babachibababa.gif
2MB, 480x270px
>>54450045
I believe in you anon
>>
File: 52505051514852555552.jpg (67KB, 1093x720px) Image search: [Google] [Yandex] [Bing]
52505051514852555552.jpg
67KB, 1093x720px
>>54449777
okay I admit this code is trash, I tried to write it as vague as possible but I fucked up. I just meant to say he can increase the pointer like that using recursion (yes I know he would need to check for the array size or some terminator).
>>
>>54450003
>Friendly Linux thread
>>
>>54450104
>there is no question
>>
File: Capture.png (7KB, 709x57px) Image search: [Google] [Yandex] [Bing]
Capture.png
7KB, 709x57px
This is the recursion question i was asking help for. hope this clears up anything
>>
>>54450045
who is this coq doc?
>>
>>54450126
what language do you want? C++? Java? C#?
>>
Why are we still using SQL in 2016? Don't get me wrong, I'm not against the relational model, but do we really have to use something so fucking unnecessarily verbose?
>>
>>54450167
what would you recommend to replace it?
>>
>>54450182
A copy of it with every keyword's length trimmed by at least 50% would be a start
>>
>>54450159

.>public
>>
>>54450126
for Java:
public void printEveryOther(int[] nums) {
if (nums.length > 0) {
System.out.println(nums[0]);
printEveryOther(Arrays.copyOfRange(nums, 1, nums.length));
}
}

>>54450182
something based on Prolog would be very neat. MongoloiDB is probably okay even
>>
>>54450214
>something based on Prolog would be very neat
already exists, google datalog
>>
>>54450206
>>54450214
so, wouldn't a dsl that "compiled" to the sql solve the problem? or do you mean the complexity of the relational algebra and how its composability is less than desired?
>>
>>54450159
java

i tried
public void printEveryOther(int[] nums){
int y = 0;

if(y<nums.length){
printEveryOther(nums[y]);
y+=2;
} else{
System.out.println(0);
}
}


But the void is causing a prob, couldnt fig it out
>>
>>54450244
>so, wouldn't a dsl that "compiled" to the sql solve the problem?
yes, it would
do you want to write the compiler for that dsl? i'll make the logo

>or do you mean the complexity of the relational algebra and how its composability is less than desired?
relational algebra itself isn't that bad. the worst thing about sql is how every implementation has to be a special little snowflake and only support half of the standard, with 20 billion extensions which are not compatible across implementations
>>
>>54450244
When a language starts using words like "as" a lot, that's a bad sign. Unfortunately that includes Python.
>>
>>54450273
y isn't static
learn how to program, christ
>>
>>54450244
it's a start. some languages already have that, and it's pretty nice. but i think there's always more left to desire once you start writing really complex queries and eventually everything becomes basically as verbose as SQL is
i dont think that has to be the case. if the DSLs focused on making PL/SQL better it would be a lot better than just trying to refine SELECT or INSERT.
>>54450273
there's no loop so you only print out the first number there. you could pass y along with the array there to make it work like a for loop. also you're printing out an extra 0 at the end. you don't even need that else {} case at all
>>
>>54450273
Before replying to anyone else or trying to rewrite this piece of code, explain to me what each piece of your program is doing. Some important points for you to address:

What does the y signify? Why are you adding 2 to it after calling the method in the first case of the if? What's the purpose of the else branch of that if? What happens when you pass nums[y] to printEveryOther?

Your code is basically a mess and it shows that you have no idea of what you want to do and/or don't know the syntax of Java at all.
>>
>>54450273
Jesus Christ
>>
If I have a biased random number generator, and an unbiased random number generator and I xor the outputs together, do I get an unbiased output?
>>
>>54450214
this might be a stupid question but do you need to import printEveryOther or is that just part of the java.lang
>>
>>54450126
const printEveryOther = (arr, i) => {
!(i % 2) && console.log(arr[i])
i++ < arr.length && printEveryOther(arr, i)
}

You're welcome, anon.
>>
File: legit.gif (1MB, 260x173px) Image search: [Google] [Yandex] [Bing]
legit.gif
1MB, 260x173px
>>54450097
>>
What do animes have to do with programming?
>>
>>54450527
>animes
>>
>>54450273
>>54450326 here, writing a post explaining the correct way of approaching this problem (please explain the reasoning behind what you posted though. If you simply copy/read this post, you'll learn 0, even if it seems to make sense)

>Write a recursive method to print every other element in an array, starting with the element in position 0.
>The method header is: public void printEveryOther(int[] nums)

Translating this to "regular" English would give us

>Your task is to print every element at an even index in an array (array[0], array[2], array[4], ...). Write a method that somehow depends on itself to accomplish this task. [This might not make much sense right now, but it will in a second]

Let's go back a few steps. What does it mean for a method to "depend on itself to accomplish a task"? Very unhelpfully: It means exactly what it says. Let's look at a mathematical definition of the factorial function:

>To calculate n!, perform the following steps:
>If n = 0, then n! = 1
>If n > 0, then n! = (n-1)! * n
>Otherwise (if n < 0), abort the calculation

The important bit are the first and second "If ..."s. Notice that to calculate n!, you need to know (n-1)! (at which point it follows very naturally from the definition of factorial that n! is (n-1)! * n). But to know (n-1)! you need to know (n-2)!, and so on and so forth until you reach a point where you can stop because you know the result of calculating the factorial for that n directly (in this case, when n = 0, you can just directly say that 0! = 1).
Does all of this make sense so far? Notice how you're pretty much just stating facts about how to calculate the factorial, but at each point in time, for any given n, you hand off the most difficult step (calculating the factorial for n-1) to the function itself, and just concern yourself with calculating n! if you already knew (n-1)!. This might seem trivial, but this "breaking down" of calculations is surprisingly useful.

(Cont)
>>
>>54450527
Absolutely nothing, people who post anime are trying to derail and ruin the integrity of these threads.
>>
>>54450393
you'd probably get biased output. for example:
you have a biased rand generator, between 0 and maxint, with 90% chance of generating an integer > 1,000,000
and an unbiased random number generator between 0 and maxint.
since you're using xor, and "small int" xor "large int" = "large int", you'll get an output larger than 1,000,000 90% of the time. assuming unsinged integers.
>>
>>54450291
What do you think i am doing dipshit

>>54450326
When i try to write this method i end up going slowly back to iteration, that y would add 2 after calling the method. The question told me to print each array but i couldnt figure it out in the if so i just left a method call there and would ask for help. the else i actually dont really need, its just something i would put out of habit.
>>
>>54450635
A B ^
0 0 0
0 1 1
1 0 1
1 1 0

For the above table, if A is biased and B (50% 1 and 0) isn't then it doesn't matter because ^ has a 50% chance of outputting 1 anyways. Xor is whatever the fuck, transitive or whatever, so it doesn't matter if A or B is chosen as the biased generator.
>>
>>54450565
>As a (very important) exercise, try implementing the previous algorithm in java. (If you have not yet studied what exceptions are, then ignore the last line of the algorithm - "Otherwise (if n < 0), ..." - and just make sure that you never call the function with an n under 0).

Now going back to our problem: We want to apply this technique of "breaking down" a calculation to this task. In other words, we want, at any given step, to be able to hand off the brunt of the work to the very function we're writing, and just use that result to calculate our desired result. In other words, we want to have something of this sort:

public void printEveryOther(int[] nums) {
//Something may have to go here
if(/*we can directly calculate the result*/) {
//Then do so, just like we did for 0! in the previous example
} else {
printEveryOther(/*something must go here*/) /*perhaps act on the result, as we did when we multiplied (n-1)! by n*/
}
}


or, without the distracting comments, this is the general schematic for our method

public void printEveryOther(int[] nums) {
...
if(...) {
...;
} else {
printEveryOther(...) ...;
}
}


>As an additional exercise: Do you understand what "public" means? Does that matter for our current task? Do you understand what void means? What does that mean for our current task (it means something very important! Consider the else branch of this if conditional - does it make sense to talk about acting on the result of calling printEveryOther if it returns void?)? Have you noticed how I've been carefully referring to all that we've been doing so far as methods and not functions? Do you know the difference between these two concepts?
>Most of these questions are tangential to what you're actually trying to achieve, but they are important to understand if you want to program in Java.

(Cont)
>>
>>54449922

Where is the CoC? Please put a CoC OP!
>>
Hey guys, I'm writing a Java application that will listen for messages on certain channels (using CometD). The implementation details of this are basically irrelevant, since I already have the base program which listens on a channel and works. The only thing you should know is that right now, everything is done in the main method and once it has established a connection and is listening, I just prevent the main method from returning so it continues listening.

My problem/question is how to get it to subscribe to more channels on command, while its already running. The only thing I can think of is to create a folder with text/XML files containing the details for each channel to listen to - the program would then scan the folder once a minute and checks if there are any new channels to subscribe to. Only I'd have no idea how to implement this, since right now the main thread sets everything up for the first channel and then I just add an empty while (true) at the end, or I join the main thread to itself, or something like that. So once it's up and running it just sits there and waits for this final instruction to complete (which it never does, hence causing the program to run forever until I stop it from the terminal from which I started it). What would be the best way to approach this? I'm completely open to rewriting the whole thing if needed.
>>
>>54450126
(define (every-other vec [i 0])
(unless (>= i (vector-length vec))
(printf "vec: ~a~n" (vector-ref vec i))
(every-other vec (+ i 2))))

(every-other (vector 1 2 3 4 5))
;vec: 1
;vec: 3
;vec: 5
>>
>>54450731
Could you kick off the details for listening on the channels in a new thread and use the main method/thread as the control thread which takes care of adding/removing channels?
>>
>>54449927
>tuning the JVM for scripting
This is exactly the kind of thing you shouldn't need to do when scripting. No one is arguing about writing an application.
public class Hello {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

vs
 puts "Hello World!"


I really don't know why anyone would use Java for scripting.
>>
Working on IP Address Management and a directory admin panel

I just finished the LDAP fancyness for putting DNS in the directory:

    domain = 'lemon.routing.example.org.'
addr = IPv4Address('10.0.254.8')

host, zone = domain.split('.', 1)
fwd = DNSRecord(zone, directory=g.directory)
fwd.domain = host
fwd.a_records.append(str(addr))
fwd.save()

host, zone = addr.get_reverse_dns().split('.', 1)
rev = DNSRecord(zone, directory=g.directory)
rev.domain = host
rev.ptr_records.append(domain)
rev.save()


I'm now going to build the GUI around it
>>
>>54450045
is that netbeans?ew
>>
>>54450870
x = other.x;
y = other.y;
>>
what are good exercises to:
- re-learn/remind Java+OOP concepts
- learn C#
both ^ at once?
>>
>>54450870
 x = x.other;

seriously?
>>
>>54450840
There's a certain type of person who has the tendency to act confident about things they have no understanding of, and unfortunately you're one of them. Try to become more self conscious in the future.
>>
>>54450704
Now comes the "hard" part of the problem: the actual programming/"breaking down" of the calculation into smaller pieces. Let's focus on the else branch of the if conditional first, for no particular reason other than I finding it more convenient to explain first.

else {
printEveryOther(...) ...;
}


So, we're at some point in our program where we know the answer to our problem isn't direct (we're not in the "base case", as we were when we wanted to calculate n! and n = 0). In other words, we know that nums still has a lot of stuff to print. But we can handwave that problem by handing it off to the function, and just concern ourselves with printing whatever number we need to print right now. [This wording may be confusing, but at some point these ideas will become so natural for you that you'll find it hard to break them down even further to explain them. Hopefully the example will clear it up.]

else {
System.out.println(nums[0]);

int[] aux_array = new int[nums.length - 2];
for(int i = 0; i < aux_array.length; ++i) {
aux_array[i] = nums[i + 2];
}

printEveryOther(aux_array);
}


Don't concern yourself too much with the aux_array/for piece, all it's doing is copying the rest of the array to an auxiliary array and passing that around instead (as you were trying to do when you called printEveryOther with nums[2]). Do you understand why this works? At any given point, all you're doing is printing whatever number there is to print, and letting someone else (who just happens to be yourself! That's recursion for you) take care of printing whatever there's left to print.

>Do you understand why simply passing nums[2] to printEveryOther wouldn't work? Can you think of any better ways of copying an array than using a for loop? (Hint: arraycopy). If you know C: ponder on why this piece of code can be used to demonstrate the utility of pointers.

(Cont)
>>
>>54450870
operator overloading is fucking cancer anyway
>>
>>54450918
you access object properties like this
object.property
//and not
property.object

in the example r is the object, in your code other is the object not x or y.
>>
>>54450887
>re-learn/remind Java+OOP concepts
Core Java for the impatient
>learn C#
Essential C# 6.0
>>
>>54450870
Everyone else has already explained your mistake, but also, you don't need to overload assignment for a class with just two doubles. You overload the assignment operator if you need to do any extra bookkeeping when you make the assignment.
>>
Nevermind I'm a fucking idiot.
>>
File: 1453751841926.jpg (13KB, 215x250px) Image search: [Google] [Yandex] [Bing]
1453751841926.jpg
13KB, 215x250px
>when you accidentally move one of the icons in your windows 7 taskbar and you're not 100% sure where it was originally
>>
>>54450929
>>54450937
>>54450960

Yeah sorry, this fucking frustrated me to no end. Thanks.
>>
In C, emulating strcmp, I wrote,
int strcmpt(const char *s, const char *t) 
{
for (; *s == *t; s++, t++) {
if (s == 0)
return 0;
}
return *s - *t;
}

which works, but I'm wondering why
while (*s++ == *t++) {

can't replace replace the for statement.
>>
>>54450921
>Exercise: Ponder on how, at each step, you're handling smaller and smaller arrays and how this relates to the notion of "convergence".

So, recapping: So far we've ensured that, at each step, we print whatever number is in the first position of the nums array and that someone else will repeat the process for all the numbers left in the array, starting at the next even position. Or, to put it in code:

public void printEveryOther(int[] nums) {
...
if(...) {
...;
} else {
System.out.println(nums[0]);

int[] aux_array = new int[nums.length - 2];
for(int i = 0; i < aux_array.length; ++i) {
aux_array[i] = nums[i + 2];
}

printEveryOther(aux_array);
}


There's only one problem left to tackle: When will the method know when to stop? At some point, as was the case with calculating the factorial, you'll need to stop this "breaking down" of the problem, lest not you keep breaking it down for all eternity (or until the JVM throws an exception). So, when exactly do you know you can stop printing numbers? When there's nothing left to print, of course. And when will there be nothing left to print? Well, the obvious answer is that there'll be nothing left to print when the array is empty. So, our base case (the point at which we want to stop breaking down the calculation) could be something like

if(nums.length == 0) {
return; //Stop!
}


And while this would work, I find it conceptually disgusting to have a return in a void method, so I'd much prefer to (equivalently) do:

if(nums.length == 2) {
System.out.println(nums[0]);
}


We're almost done, but there's still an edge case to consider: What if nums' length were odd? Say it were 7. Let's work through an example with random numbers:

(Cont)
>>
in C#, how do you manipulate/acces a property of an through a parameter in a method? For instance i want to sort fraction object (1/6, 1/4, 1/2....) on a property like numerator, denom, fraction value, etc.

I HAVE TO QUICKSORT MYSELF because school

public struct Fract() // my fraction object
{
public int num;
public int denom;
public float fraction; //1/3 = 0.33333

//optional properties
public string name;
public bool IsPrime;
//etc

}

void Quicksort(ref Fraction[] array, int p, int r, PROPERTY)
{
.... Yadada
Split(ref Fraction[] array, int p, int r, PROPERTY)
...
}

static int Split(ref Fraction[] array, int p, int r, PROPERTY)
{
pivot = array[r].PROPERTY;
//... etc rest of method
}

how am i gonna dynamically access an object's property through a method?
>>
File: Capture.png (13KB, 746x281px) Image search: [Google] [Yandex] [Bing]
Capture.png
13KB, 746x281px
>>54450214
every other?
>>
File: weather.jpg (160KB, 1366x768px) Image search: [Google] [Yandex] [Bing]
weather.jpg
160KB, 1366x768px
I don't know what to do, this thing isn't working and I can't see what I did wrong. When I try to run the html I see "El clima".
Help /g/.
>>
>>54451113
ohh whoops, it should be 2 instead of one there
>>
>>54451101
for instance, if my Property parameter would be 'Numerator', i want the compiler to access array[x].Numerator.
>>
>>54451135
and i guess you should check for nums.length > 1 instead of > 0
to be fair i was super tired when i wrote that and fell asleep literally 5 minutes later
>>
>>54451057
Whoah, I'm not the anon this is directed towards, and this is kind of tldr for me cause I'm having a headache, but I applaud you for doing this. I tutor people in CS regularly (irl), so I know this can be hard sometimes.
>>
File: Capture.png (23KB, 1021x303px) Image search: [Google] [Yandex] [Bing]
Capture.png
23KB, 1021x303px
>>54451135
???
>>
>>54451166
see >>54451157
>>
>>54451048
Suppose the strings actually are identical. That loop will advance all the way past the delimeter and then overflow. Checking for *s == 0 in the body of the loop doesn't work because you're using a post-increment, meaning after the comparison s will be incremented anyway. Try this version:

int strcmpt(const char *s, const char *t)
{
char c;
while (*s++ == (c = *t++)) {
if (c == '\0')
return 0;
}
return *s - *t;
}
>>
>>54451124
Put the script at the bottom of body or wrap it in $(function() { }) so it fires when the dom is loaded ready.
>>
>>54451178
Whoops, this is wrong too, you have to save a character from s as well, for the final return.
>>
Is there any particular reason why people are making copies of the array rather than simply calling a recursive helper method?
>>
>>54451057
>Erratum: The braces are not properly matched in the first code block of the previous post. Fixing them should be trivial, and is left as an exercise to the reader.

nums: [13 42 12 97 93 75 37]
screen:

>One step

nums: [12 97 93 75 37]
screen: 13

>One step

nums: [93 75 37]
screen: 13
12

>One step:

nums: [37]
screen: 13
12
93

>Problem: nums' length is not 2, so we'll fall through to the else branch. Now we'll try to work with an aux_array of length nums.length - 2, which is to say, of length -1. Boom!

The solution? Well, if nums' length is 2, OR LESS THAN 2, then we can stop. Easy!

if(nums.length <= 2) {
System.out.println(nums[0]);
}

>Exercise: Would the same problem have arisen if we'd used nums.length == 0? If it would have, then what would the solution have been? Compare the solution for both cases and ponder upon it.

So, finally, the method would be:

public void printEveryOther(int[] nums) {
//Notice how there's nothing else to be done, so we end up not needing anything where these first ... used to be
if(nums.length <= 2) {
System.out.println(nums[0]);
} else {
System.out.println(nums[0]); //LINE 1 - SEE BONUS EXERCISE

int[] aux_array = new int[nums.length - 2];
for(int i = 0; i < aux_array.length; ++i) {
aux_array[i] = nums[i + 2];
}

printEveryOther(aux_array); //LINE 2 - SEE BONUS EXERCISE
}
}


>Exercise: What could you do to improve this method? There's a very simple modification that you could do when you compare both branches of the if conditional. Can you see it?

(Cont)
>>
>>54451209
frgt it
>>
File: image.jpg (408KB, 1600x2133px) Image search: [Google] [Yandex] [Bing]
image.jpg
408KB, 1600x2133px
Just teaching a "Girls Who Code" workshop, they are coming for your jobs /dpt/ :^)
>>
>>54451300
damn those are some nice legs
>>
>>54451240
>Bonus exercise: Say that you were given an extra restriction: You may only call System.out.println(...) after having called the function itself, printEveryOther(...). Would it still be possible to print the numbers in order? (i.e. the number at index 0 is printed before the one at index 2 and so on)
>Hint: Think backwards! Instead of starting at nums[0], what would happen if you simply put LINE 1 after LINE 2 and printed the last number in the array instead? Step through a few example arrays as I did previously and ponder on the conclusion **before** implementing the solution in code.

>Bonus exercise 2 (easier than the previous one): Copying the array so many times is wasteful. Can you think of a way of avoiding this? (inspired by >>54451236)
>Hint: At each point, you need to know what index you're at. Ponder on this fact and write the following recursive method:

printEveryOther_aux(int[] nums, int index) {
//Your code goes here
}


which will be called in printEveryOther as as such:

printEveryOther(int[] nums) {
printEveryOther(nums, 0);
}


(END)

Any questions?

>>54451163
Thanks. I really enjoy teaching others as long as they're not wasting my effort. I'd gladly tutor a few kids for free if I knew how to reach them.

>>54451236
Because that's an efficiency detail which doesn't matter at all for the kernel of the task he's doing. It's more important for him to understand recursion right now.
>>
>>54451300
Jokes on you, I'm NEET.
>>
File: 1454570895782.png (111KB, 417x234px) Image search: [Google] [Yandex] [Bing]
1454570895782.png
111KB, 417x234px
>>54451300
fk
>>
>>54451300
What kinda school lets girls wear heels that high, and where can I apply for a staff position?
>>
>>54450946
thanks!
>>
File: creep.png (248KB, 1100x1066px) Image search: [Google] [Yandex] [Bing]
creep.png
248KB, 1100x1066px
>>54451300
>nice try

>>54451331
>tutor a few kids for free
That's kind of what I do. I find it fun too as long as it doesn't get too demanding. I've been thinking about taking on more people for money.
>>
>>54451300
It won't be long before programming is seen as a women's field like secretarial work and nursing.

I want off this ride.
>>
>>54451209
im dumb
public static void printEveryOther(int[] nums) {
if (nums.length >= 2) {
System.out.println(nums[0]);
printEveryOther(Arrays.copyOfRange(nums, 2, nums.length));
} else if (nums.length == 1)
System.out.println(nums[0]);
}

>>54451236
i was thinking of it as pattern matching and trying to keep it concise
for example: https://glot.io/snippets/eei10hympt
>>
>>54451300
I want her to battle my patriarchy.
>>
>>54451331
>Because that's an efficiency detail which doesn't matter at all for the kernel of the task he's doing.

It's also a simplicity detail.
>>
>>54451340
stop capitalizing it

and you ARE a neet not your "neet"
>>
>>54451331
>efficiency detail
Not copying the array isn't really complicated. You just increment an index.
>>
What do you guys think of generics and are they used alot?
>>
>>54451300
HNNNNNNNG
brb, going to the bathroom
>>
>>54451415
Go doesn't need them so they are objectively shit.
>>
>>54451331
Obviously the last code block should be

printEveryOther(int[] nums) {
printEveryOther_aux(nums, 0);
}


instead.

>>54450654
>When i try to write this method i end up going slowly back to iteration, that y would add 2 after calling the method.
But notice how adding 2 to y will not achieve anything, since y is a local field (meaning it doesn't exist outside the function) and you exit the function right after adding to it. Try running the exact same piece of code without the y+= 2; line and you'll see that you get the exact same results.

>The question told me to print each array but i couldnt figure it out in the if so i just left a method call there and would ask for help.
Asking for help is great and practically a necessity in this field, but "just" doing things for no reason will not net you any sympathy in most circles. Always try to have a justification for what you're doing. It would be much better for you to just have a comment explaining your reasoning without any actual code than to have a piece of code you don't understand.

>the else i actually dont really need, its just something i would put out of habit.
Similarly to what my previous point, don't do things out of habit. If you don't understand what you're doing then you're not programming (writing algorithms), you're just "programming" (trying to get the compiler/interpreter to accept random semi-coherent shit just like an alchemist mixing random shit to make the philosopher's stone).
>>
File: plebs.jpg (121KB, 440x626px) Image search: [Google] [Yandex] [Bing]
plebs.jpg
121KB, 440x626px
>>54451403
>not capitalising acronyms
>>
>>54451415
Good from a usability standpoint, shit from a runtime/compile time costs.
>>
File: 2.png (91KB, 550x385px) Image search: [Google] [Yandex] [Bing]
2.png
91KB, 550x385px
I fucking hate when programming books don't have any exercises or try to be textbook baits, throw 50 after each chapter, with no answers, and they turn out to be 3-5 clusters of exercises referring to the same thing, most of them feeling very forced. No answers means you can't just skim some of them to save time or check if your solution was optimal. The instructor's manuals available only for the teachers is the most retarded thing ever. if you can't solve the exercises you rate, you should be thrown out on the street. I just want programming books to have 3-5 carefully selected and challenging exercises after each chapter, with fully worked solutions
>>
File: memewave.jpg (211KB, 1280x720px) Image search: [Google] [Yandex] [Bing]
memewave.jpg
211KB, 1280x720px
What's the vaporwave of programming languages? I'm thinking APL or J
>>
What's the point of importing a sub-class vs the entire class? Is it because its faster?

Example,

Import system;
Vs
Import system.object;

Shouldnt imorting system already include object?
>>
>>54450414
It's defined right there, you don't need to import it. That's how recursion do.
>>
>>54451491
C#
>>
>>54451392
>>54451407
It's not a matter of being complicated or not for someone that already dominates the topic. While it's a very simple detail (one I actually didn't think of at first, despite knowing there was a simpler way of doing it which didn't involve copying the array), it's best to avoid adding unnecessary complexity to a problem when you're using it to teach new concepts, no matter how small the complexity may seem.
>>
>>54451491
C+= obviously
>>
I disagree. A vaporware programming language would have no implementation or an implementation lacking compared to what was promised.

Nice pic though.
>>
What's the best way for inputting additional data/commands into an already running java program?
>>
>>54451221
Now I really don't understand what's going on. It isn't working.
>>
>>54451556
VaporwaVe not vaporwaRe.

Vaporwave is an autistic music genre

https://www.youtube.com/watch?v=cU8HrO7XuiE
>>
I'm working on a random maze generator using prim's algorithm in C++. I kind of fucked up by making my graph a vector of vectors of pairs of vertices and integers (weights). I thought the jagged array approach was so totally cool becky but it actually blows chunks and now I don't want to redo everything.
>>
>>54451604
Are there any errors in the console? What data are you getting if any? Where are you putting the script? This is important because it's JSONP which inserts its own <script> tag into the DOM.
>>
Scheme is so fucking good. Lists are the best.
>>
>>54451491
Oh fuck, I read that as vaporware too.

In that case, I change my answer to VB6.
Literally everything it can do can also be done in C#, and you can even run a tool built-in to visual studio to convert VB source code to C#.
Anyone still editing VB source files in their native format is a fucking hipster to the highest degree.
>>
>>54451647
Hope you are using m-expression as McCarthy intended LISP to be written
>>
>>54451672

M-expressions are superior, but sadly, s-expressions are everywhere.
>>
I already know Java.
Should I learn C# if I want to improve my chances for getting a software engineering job in the industry?
Should I stop being a Linux fag if I want to make it in software engineering?
>>
>>54451511
Because java is retarded, when you import a superclass it'll take ages to do a load of background work sifting through everything, whether or not you use any of it.
This is part of the reason why it's practically impossible to write java without an IDE.

Even if you know exactly what libraries you need to import, as soon as you're not using it anymore, how do you even remember which library to no longer import?

Also it'll pollute the namespace with a load of shit you probably don't want, and could cause clashes you wouldn't dare imagine.
>>
File: vb6wave.gif (37KB, 832x590px) Image search: [Google] [Yandex] [Bing]
vb6wave.gif
37KB, 832x590px
>>54451659
Good answer anon, now to find a VB6 to javascript compiler and rewrite my startups frontend in it.
>>
>>54451695
I see, thanks, though i was mainly talking about C#.
>>
>>54451639
>weather.js:9 Uncaught ReferenceError: $ is not defined

I'm pretty much a newfag, but I thinks the error it's related to ajax.
>>
>>54451548
In case any of you missed out on the good giggles:

http://blog.mollywhite.net/why-im-not-laughing-at-c-plus-equality/
>>
>>54451695
This wouldn't be considered premature optimization right?
>>
>>54451491
TurboPascal
>>
>>54451738
You are missing jQuery on your page, add this script tag in <head> BEFORE weather.js

<script src="https://code.jquery.com/jquery-2.2.3.js"></script>
>>
File: kush.jpg (226KB, 1292x848px) Image search: [Google] [Yandex] [Bing]
kush.jpg
226KB, 1292x848px
>>54451717
>gif

That image is older than half of the people lurking this site, now that is vaporwave.
>>
>>54449922
great bod, seductive feet

i want a ft job :(
>>
>>54451777
I forgot the JQuery... you saved me. Thanks based anon.
>>
>>54451491
FORTH

> tfw you will pop a value of your stack while being dominated by a space womyn in far flung future
>>
>>54451379
you know i was thinking of using this but the possibility of my teacher finding it freaks me out. does google search show rebecca black posts or is it too obscure?
>>
>>54451687

>Should I learn C#
Yes, regardless. It's very much like Java but better as a language in many ways. Both Java and C# are very popular as far as enterprise, so knowing both gives you options.

>Should I stop being a Linux fag
In general, no. But know Windows basics in case a position requires it.
>>
File: forth_on_the_atari.jpg (62KB, 450x722px) Image search: [Google] [Yandex] [Bing]
forth_on_the_atari.jpg
62KB, 450x722px
>>54451808
no i forgot the image :(
>>
>>54451757
Not really, if you don't bother to do the imports properly from the start, nobody is going to fix them later.

It's generally just a good idea for readability too, so someone looking at your code as plaintext can tell what specific libs you are using.
>>
>>54451403
>>54451434
*you are A neet
>>
>>54451723
Well that makes things slightly different (I imagine that C# is smarter about how it handles imports) but the point about namespaces remains.
>>
How do i know if im a master at c#?
What defines my tier of c# programming? I want to tell employees im a master, but i dont know
>>
>>54451833
https://en.wikipedia.org/wiki/NEET

(You) are a PLEB.
>>
>>54451845
Write a C# compiler, then you are a master of C#.
>>
File: glo man.jpg (172KB, 667x667px) Image search: [Google] [Yandex] [Bing]
glo man.jpg
172KB, 667x667px
>>54449922


function analyzePage(thisPage) {
var webPage = require('webpage');
var page = webPage.create();

page.open(thisPage, function (status) {
if (status === 'fail') {
console.log("Error failed to open webpage. ");
phantom.exit();
}

var rawcontent = page.plainText;

// file system junk:
var fs = require('fs');
var path = 'outputdata.txt';
fs.remove("outputdata.txt");
fs.touch(path);
fs.write(path, rawcontent, "w");

});

var fs = require('fs');
var rawcontent = fs.read('outputdata.txt');
console.log('read data:', content);

// a bunch of trivial sorting and counting here

var ret = [dataStrings, dataFrequency];
return ret;
}

output = analyzePage("http://webscraper.io/test-sites/tables");



I've spent hours on this bit of javascript:

the root of my problem is I don't understand page.open() of phantomjs.

why does it have a function as an argument? how do I get it to return a value to the rest of the program? It wasn't my first choice to try to write the page.plaintext into a text file only to read it again 5 lines later (even that doesn't work)
>>
>>54451864
there is no need to capitalize acronyms, its stuoid. Just use periods
>>
>>54451930
declare a variable outside of the page.open() and set it inside to page.plainText
then just use that from outside the page.open() shit
>>
>>54451930
>the root of my problem is I don't understand page.open() of phantomjs.

PhantomJS open is asynchronous like most I/O operations in NodeJS, rewrite analysePage to take a callback as well.


function analyzePage(thisPage, cb) {
var webPage = require('webpage');
var page = webPage.create();

page.open(thisPage, function (status) {
if (status === 'fail') {
console.log("Error failed to open webpage. ");
phantom.exit();
}

var rawcontent = page.plainText;

// file system junk:
var fs = require('fs');
var path = 'outputdata.txt';
fs.remove("outputdata.txt");
fs.touch(path);
fs.write(path, rawcontent, "w");

cb(rawContent);
});


}

analyzePage("http://webscraper.io/test-sites/tables", console.log);

>>
>>54451955
>Listening to a faggot who doesn't capitalise anything, ever

>>54451933
1) What I mean is that just because a language is built with efficiency in mind, doesn't mean that anyone using that language will be using best practise.
Of course some people do, but badly written C++ is truly terrible, more so than any other language I have encountered.

2) Making games or making engines, because you don't make games in C++ anymore that much is for sure.
>>
>>54451978

didn't work
>>
>>54451930
imagine if archaeologists in a distance future dug up that thing lmfao
>>
>>54451845
>>54451929
Honestly, that wouldn't even do it. Knowing strictly how the language works doesn't mean you know how to use critical parts of the standard library. I've taken proficiency tests with staffing agencies, and they ask some very detailed questions when you get to the higher levels. Do you know what the compiler name-mangles anonymous types and functions to? Do you know how to call an internal method in an assembly from outside that assembly? Do you know everything there is to know about reflection, and interop? There's a ton of nooks and crannies. You can be pretty proficient without knowing every detail, but mastery means mastery. It's not a word to be taken lightly.
>>
>>54448643
No, this gives
error: `a` does not live long enough
let tmp = a.do_it()
^
>>
>>54449922
What programming language is best for making games?
>>
>>54452171
Whatever you feel most comfortable with, anon.
>>
>>54452171
APL
>>
>>54452171
Forth
>>
>>54451597
dont know what you're trying to do, but maybe use a messaging thing like RabbitMQ or sockets?
>>
>>54451995

I still don't get the point of the callback function
>>
>>54452171
Malbolge.
>>
>>54452197
Heard that cpp was best, but i'm getting roasted for saying it's a powerful language.
>>
>>54452171
Jai
>>
>>54452244
cpp is the worst, try a memelang instead
>>
>>54452244
The language you know the best is objectively the best language to make a game in.

Just make something. If your language is turing complete, you can make literally anything.
>>
>>54452031

> This is "Gloman" the sun god
> it was owned by a warrior chief named "Keef"
>>
>>54452211
The point is to no block I/O, like that's the entire point of node.js m8
>>
>>54452171
If it's a complex/large-scale/3D game that will demand high performance, C or C++, or use a middleware engine

Otheriwse
>>54452197

>>54452203
>>54452204
>>54452233
Memes

>>54452246
Underrated meme

>>54452261
Nigga please. You have to take performance into account for at least some cases
>>
What have done today to try and stop a Donald Trump presidency?

http://gizmodo.com/facebook-employees-asked-mark-zuckerberg-if-they-should-1771012990
>>
>>54452292
Thanks. Now I know that I haven't been wasting my time on a useless language.

Do you know any intermediate cpp books that I can use to continue learning about cpp?
>>
>>54452275

I don't know what the point of node JS is

I didn't realize I was using it...
>>
>>54452351
Jesus Christ.
>>
>>54452351

This politics in tech thing really needs to end.
>>
>>54452351
>stop
It's like you hate fun.
>>
File: 1461195174142.jpg (99KB, 600x413px) Image search: [Google] [Yandex] [Bing]
1461195174142.jpg
99KB, 600x413px
>>54452445
This jungle woman obsession needs to stop
>>
>>54451372
you mean like how it used to be? when computers were humans (but still called computers) and was mostly a field for women?
>>
File: kek.gif (3MB, 286x258px) Image search: [Google] [Yandex] [Bing]
kek.gif
3MB, 286x258px
>>54452480
>jungle woman
>>
>>54450273
>>54450654

Did you actually end up reading
>>54450565
>>54450704
>>54450921
>>54451057
>>54451240
>>54451331
>>54451432

Or not? You ended up disappearing, which leads me to believe you just took the code and ran, in which case ĂŽ want you to know I fucking hate you.
>>
>>54452418
I recommend Stroustrup's The C++ Programming Language (4th Edition), Gregory's Game Engine Architecture (2nd Edition), and Sutter's Guru of the Week articles.
>>
>>54452480
>likes white girls
you're literally just as bad
>>
>>54452171
Rust
>>
>>54452577
What do you like then?
>>54452587
kys
>>
>>54452587
Stop impersonating the hime poster, thanks.
>>
>>54452604
chinks
>>
I have an interview for a programming job Friday. I have no degree. Am I fucked?/What should I study.
>>
File: objc.png (182KB, 500x700px) Image search: [Google] [Yandex] [Bing]
objc.png
182KB, 500x700px
http://dev.to/rly have fun /dpt/ :3
>>
>>54452480

Jungle women are apolitical, though.
>>
>>54452629
You're not me, go away.
I never post lewd.
>>
>>54452577
>>54452651
>having a "type"
Stay primitive, my monkey friends, life is easier that way.
>>
This is for a project in my Java datastructures class. I'm suppose to modify the book's source code for Hashmaps. I was curious about this part.

*as a starting point, modify class MapEntry in class AbstractMap.java to include the extra field for the next reference.
Where would I add this next reference? I'm a little confused on where to put this next reference or how I could implement the next reference in the code below

  protected static class MapEntry<K,V> implements Entry<K,V> {
private K k; // key
private V v; // value

public MapEntry(K key, V value) {
k = key;
v = value;
}

// public methods of the Entry interface
public K getKey() { return k; }
public V getValue() { return v; }

// utilities not exposed as part of the Entry interface
protected void setKey(K key) { k = key; }
protected V setValue(V value) {
V old = v;
v = value;
return old;
}

/** Returns string representation (for debugging only) */
public String toString() { return "<" + k + ", " + v + ">"; }

>>
>>54452684
Stop pretending that you're me.
Piss off.
>>
>>54452752
If you're really me, then how many photoshop layers did you use to create the hime holding K&R pic?
>>
File: 1448561031003.png (1MB, 1702x2471px) Image search: [Google] [Yandex] [Bing]
1448561031003.png
1MB, 1702x2471px
>>
>>54452762
trick question. gimp
>>
so i'm looking to make a basic messenger app for ios that i'm hoping to monetize, how awful would it be to write the backend myself?
>>
>>54452275

So is it basically like hardware interrupts?
>>
>>54452835
Choose a language that has sane eventful primitives and not at all.
>>
>>54452883

neat, then i'll get to it.
most tutorials online i find are all based on using some third-party API but i'm just not down with that.
>>
>>54452351
gaysbook
>>
char A[X][Y];
while(scanf("%s",A[i])!="*END**")...


returns error: comparison between pointer and integer
can somebody please explain
>>
>>54452947
Try Go's channels or Node's EventEmitter.
>>
>>54453000
good for you. how much do you make?
>>
>>54452975
scanf does not return a string. You can't compare strings directly in C anyway.
>>
>>54452975
>scanf("%s",A[i])!="*END**"
scanf returns an integer, which equals the number of elements read. "*END**" is a string literal, of type char * (technically not true, but close enough).
You're comparing an integer to a pointer, which isn't valid.
Also, that's not how you do a string comparison anyway. You need to use strcmp to compare strings.
char A[X][Y];
do {
scanf("%s", A[i]);
} while (strcmp(A[i], "*END**") != 0);

or something similar.
>>
>>54453000
the tip should be another smug pepe face
>>
>>54452975
check what scanf returns. is it the same as a char pointer? no? there you go you mongoloid

why is dpt plaggued by idiots who can't use the man pages
>>
I'm writing a software rasterizer based on the opengl pipeline, for educational purposes. It runs like total dog shit right now and I haven't even implemented texture mapping or lighting yet.Oh boy.

>tfw there are people out there that can get 100k triangles up on screen in realtime while I can barely get 50.
>>
>>54453022
so barely enough to pay rent? i'm not envious.
>>
>>54453060
>what are autism bux
>>
File: wtf.jpg (23KB, 306x227px) Image search: [Google] [Yandex] [Bing]
wtf.jpg
23KB, 306x227px
>>54452975
>wants to use an array of strings
>declares 2D array of chars

Just stick to php.
>>
Whats a good book for lua?

>>54452534
just got back and notice you responded to my response, and thats alot of shit. ill get to it.
>>
File: awe.jpg (17KB, 384x384px) Image search: [Google] [Yandex] [Bing]
awe.jpg
17KB, 384x384px
>>54453000
>>
>>54453075
>>declares 2D array of chars
That is sufficient for an array of strings. They all just have the same amount of space allocated to them.
>>
>>54453080
It isn't even useful for what its main purpose supposedly is.

Lua's FFI makes me want to die. So much goddamn boilerplate to hook it up to C.
>>
>>54453100
It's implemented the same, but the syntax is abhorrent.

Also the declaration implies you want an array of independently-accessible char arrays, when the 2nd dimension is never actually used.

Keep It Simple, Stupid.
>>
>>54453075
>does not know how C works
Stick to php.
>>
>>54453080
I'll be here
>>
>>54453138
>It's implemented the same, but the syntax is abhorrent.
The same as what? C doesn't have a string type.
An array of char *s is NOT equivalent, as you would need a malloc space for every string.
>>
>>54453136
The main benefit of lua is that it doesn't require compilation.

Don't look at it as a programmers scripting language, look at it as a user's configuration tool.
Next time a customer wants to tweak something, instead of having to recompile a whole new installation package for that one change, you just modify a script and send it over to them to run.

If the interface to C isn't general-purpose, you're doing it wrong.

>>54453157
>Using misleading syntax as long as it compiles is a-okay :^)
>>
>>54453175
>C doesn't have a string type.

That's why it belongs in the garbage.
>>
You watching GoT guys?
>>
>>54453136
I need it for a game so i dont care WHAT you think
>>
>>54453181
you're the one who belongs in the garbage
>>
>>54453191
no
>>
>>54453181
Nobody cares about your opinions, race mixer.
>>
>>54453200

nuh-uh!
>>
>>54453204
it's time to stop
>>
>>54453191
No, and that shit is not programming related.
>>>/tv/
>>
>>54453191
No.
>>
>>54453054
Hello narcon
>>
>>54453175
If the strings are runtime-dependant, it's going to be a pain in the ass either way.
The code isn't length checking, so the 2D char array might not be big enough to contain them anyway, unless you're using dynamic sized arrays, in which case it's malloc either way.

>An array of char *s is NOT equivalent, as you would need a malloc space for every string.
They're comparing to a string mutated by a call to scanf, why would you not want to use (char *) ?
>>
>>54453200
both C and OSGTP belong in the garbage
>>
>>54453181
It does have a string type though. char *.

>>54453179
Scheme does this much better though. You can hook it up to C in 1 line with Chicken's implementation. It makes things faster and easier to debug.
(bind* "#include \"engine.h\"")


>>54453196
Wrote multiple games, use scripting with Scheme. Trust me Lua is really awful. I'm speaking from personal experience.
>>
>>54453241
you and people who espouse similar opinions about C are the ones who belong in the garbage
>>
>>54453181

got to hell tripnigger
>>
>>54453238
>The code isn't length checking, so the 2D char array might not be big enough to contain them anyway, unless you're using dynamic sized arrays, in which case it's malloc either way.
I know. The original code isn't good and scanf on unbounded strings (or scanf in general) shouldn't be used. However, if you're generous with the buffer size, you should have enough space for any reasonable input. If it requires strings of ANY possible length, then yes, something malloc based would be required.
>They're comparing to a string mutated by a call to scanf, why would you not want to use (char *) ?
Automatic memory (stack based) is nicer to deal with.

>>54453247
>It does have a string type though. char *.
char * doesn't count as a proper string type. A string in C is a sequence of zero or more (multibyte) characters followed by a null terminator, including the terminator. A char * doesn't guarantee that the null terminator exists.
For example:
char [4] = "test";

is NOT a string in C, as the null terminator does not exist.
>>
>>54453288
>char [4]
forgot the identifier
char a[4]
or whatever.
>>
>>54453247
lua is so bad that even smug lisp weenies can rightfully talk shit about it
>>
>>54453288
You're actually incorrect though. Null terminated strings are not the same thing as strings. The most notable example is many filesystems have fixed length entries for things like name fields, and as such do not care about whether they end in \0.
>>
>>54453211

I can't. I'm here forever.

>>54453288

String literals have a null terminator. char* is still not a real string type, though.
>>
What do I learn first, c or c++?
>>
>>54453288
>tfw I always thought string constants were appended with the null character terminator as they were declared because it stores an additional byte for it in memory
>>
>>54453247
no its a mod for a game
>>
>>54453304
Hey man I've been down the Lua FFI road and am giving advice.

((smug-lisp-weeny-pride))

>>54453322
C for sure. C++ is a clusterfuck and C is the most useful language to learn. So many important, useful, and quality libraries are written in C.

Honestly C is probably the most important language to know and this is coming from a smug lisp weenie.
>>
File: feelscrying.jpg (60KB, 700x700px) Image search: [Google] [Yandex] [Bing]
feelscrying.jpg
60KB, 700x700px
>have a "static const someclass* ptr" in a class "Object"
>can't do "Object::ptr = initedclass" in a function
>can't do it globally since my function inits libs required by someclass

Ah shit.
>>
>>54453353
C it is, thank you
>>
>>54453319
C does not have a string type. C's type system is extraordinarily simple, as it was intended to be. C has capabilities for representing strings, along with some syntax and some library functions for manipulating data in this way, but it does not have a "string type".
Happy? Okay all you guys can stop arguing about strings in C now.
>>
>>54453375
ok, C doesn't have strings, fine

but does it have the ability to average two integers?
>>
>>54453322
Learn C, and don't bother with C++. C++ made sense in the 90s, but these days there are better high-level languages than C++, and C is still a better low-level language.
>>
>>54451749
Why I'm Laughing at C Plus Equality (pro tip it's this article)
>>
>>54453385
I was trying to explain that C DOES have strings, but it doesn't have a "string type". It has character types, it has pointer types, and it has functions for manipulating >strings< as character pointers.

>does it have the ability to average two integers
yes

>>54453388
>>54453353
>>54453374
Also in agreement that you should learn C before C++. I pity the poor souls who learn C++ as their first ever programming language
>>
>>54453322
java
>>
>>54453308
That's the definition of string given by the C standard. Anything else is not a C string.

>>54453319
>>54453334
>String literals have a null terminator
A specified the exact size of variable, so it is not present.
It's the same as if I did
char str[4] = {'t', 'e', 's', 't'};
>>
>>54453375
typedef char *String


Next thing you'll be telling us that C doesn't have a byte type either.
>>
>>54453429
that doesn't work
>>
>>54453423
I know an okay amount of java already desu
>>
>>54453428
Which is exactly why if you were using fixed length char arrays, you would set str[len] to 0.

Just because C allows you to make strings non-functional doesn't stop them being strings.
>>
>>54453438
then C++
>>
>>54452271
>not to be mistaken with his compatriot, Waka Flaka of Flame.
>to express virility, at gatherings his adherents would intone his famous battle cry: "BOW
>>
>>54453428
>A specified the exact size of variable, so it is not present.

I guess I wasn't paying attention, because I didn't notice that.
>>
>>54449922
So I want to make an Android and iOS app for a business in town. I am going to meet tomorrow with the guy to discuss it. I haven't had a job interview in like 4 years, so I am a little rusty.

He was kind of concerned that I had not published a finished mobile app before. I made a prototype for a course last year and I showed him the GitHub repo, but it wasn't in the Google Play store. He wants the app to run on iOS and Android, so I am thinking about using Xamarin Studio so I can have one code base. My experience with C# is limited, but I have never used Swift so it's probably a better choice.

The app idea is really simple. He wants to put his website into an app. This will involve displaying menus, text information, contact information, searching the app, and an email box to contact him from the app. It's really simple and the core functionality is similar to what I made in my software engineering course last year so I think I can do it.

How should I impress him to make him think I can get it done? I am going to install Xamarin on my laptop and see what I can do on it today.
>>
>>54453429
>your logic
Does C have garbage collection?
If not, how come I can make a garbage collector in C? See, C is garbage collected
>>
>>54451749
i doubt she unironically believes in trigger warnings and whatever dumb shit, she's just turning it into a career
>>
>>54453437
Sure it does.
>>
>>54453422
typedef char * string;

What now punk?

>>54453428
The C standard can go fuck itself. It has no authority over me. In actuality, C string != string. C string is a term of art for null terminated strings, which are pretty much exclusively used in C.
>>
don't google image search C string
>>
>>54453528
what the fuck
>>
>>54453514
>The C standard can go fuck itself. It has no authority over me
That is literally the most retarded mentality you can have.
You can have your own string type, but it's not a C string.

>typedef char * string;
As explained before, not a C string.
>>
>>54453491
size_t and bool aren't types now?
>>
>>54453491
If you can implement something in a single line, it's taking up as much space as a single #include or #define, which is as good as a built-in to me.

Go ahead and implement GC in one line (no more than 80 columns :^)).
>>
>>54453560
>reading comprehension.
I said in that same post that C strings are distinct from strings. C strings is C-ese for null terminated string.
>>
>>54453505
nope, you forgot the semicolon
>>
>>54453567
You moved the goalposts. It was never about "in how many characters you can implement a feature", it was about "does the language come with the feature"
Also, considering every single built string function doesn't use a typedef, I would say that C is meant to rely on char pointers.
>>
>>54452976
why not Erlang or Elixir? for reference, WhatsApp uses Erlang and Facebook used to use it for the chat. also battle.net's chat servers were created with Erlang
>>
>>54453584
You're writing a fucking C program. The standard defines what a string is. You can't say "fuck the standard". If you're not following the standard, you're not writing C.
You can come up with your own string definition, but it won't be the canonical definition of a string in C.
>>
>>54453616
>string in C
>same thing as C string
Come on man. Learn how English works. They aren't the same. And not conforming to standards doesn't mean one isn't writing in C, but it means that one isn't writing in canonical C.
>>
>>54453612
Because gotards think go invented multiprocessing and the inability to run tasks in parallel in the same program.
>>
>>54453598
The language comes with stdio, but you have to include it first.

If writing a typedef to get a string type is considered "not a language feature" then neither is prinf, by your logic.
>>
>>54453761
Not sure if retarded or just pret-
>ctard
Oh.
>>
>>54453645
You clearly don't understand how a standard works.
>>
>>54453761
The standard library is not part of the language.
>>
>>54453824
So you're saying C doesn't support strings OR print formatting now?
>>
oh my
this thread is retarded
>>
>>54453824
A hosted C implementation must provide all of the non-optional standard library features. The standard library doesn't exist in a vacuum.
If you're talking about freestanding C, that is a different story.
>>
>>54453528
I did that when I was like 10 trying to learn C
>>
guys i need help
i have 24 hours to implement an algorithm to average two integers in C but my professor says
int c = (a + b)/2
is wrong, what do i do? how do you average two integers in c?
>>
>>54453836
Try checking out Plan 9 C. The standard library is completely different. In particular, Unicode is much more closely integrated than ASCII. Conventional C compilers still compile it, so it's still C.

I would say C doesn't have a built-in string type, but C programs can clearly use and manipulate strings.
>>
how would you learn a programming lang with an android tablet? I mean, how would you write, and test, your programs in and android environment?
>>
>>54453836

C doesn't, by default, support anything except egregious security vulnerabilities.
>>
>>54453910
download an ocaml interpreter (i have one on my phone for all my metalanguage coding needs on the go)
>>
>>54453865
>this meme, again
>>>/trash/
>>
>>54453865
It's right except sometimes the code will unnecessarily overflow. Try:
long ai = a;
long bi = b;
int c = (int)((a+b)/2);
>>
>>54453865
Does he specify what type he wants the output to be?
>>
>>54453865
Haven't used this pasta in a while now:

// Won't compile on C89 if long type is not bigger than int
// Exotic type sizes need not apply; it's a Feature™ :^)
#if ((LONG_MAX) > (INT_MAX))
#define AYY long
#elseif ((LLONG_MAX) > (INT_MAX))
#define AYY long long
#endif

int avg(int n1, int n2) {
AYY sum = (AYY) n1 + n2;

return (int) (sum / 2);
}


Or general case:
// Won't compile on C89 if long type is not bigger than int
// Exotic type sizes need not apply; it's a Feature™ :^)
#if ((LONG_MAX) > (INT_MAX))
#define AYY long
#elseif ((LLONG_MAX) > (INT_MAX))
#define AYY long long
#endif

int avg(int nums[], int s) {
AYY sum = 0;
for (int i = 0; i < s; i++) {
sum += nums[i];
}
return (int) (sum / s);
}


Anyone using individual half-values or modulo isn't just on the spectrum, they're setting new records.
>>
setting up a webrtc server and client

mum is asleep so i have some time to burn

happy mothers day everyone
>>
>>54453054
Are you me ?

I'm also writing a software rasterizer, that uses packed vectors to draw faster.

>100k triangles up on screen in realtime while I can barely get 50

Don't lose hope, anon, the area of drawn triangles affects performance, too.

You can probably reach a few hundreds of small triangles at 60 fps.

Also
>100k triangles up on screen in realtime

Is there code somewhere online ?
>>
>>54453935
he says this might still overflow because there's no guarantee of long > int

>>54453941
he wants it to be an int

>>54453995
he says this may overflow as well
>>
Goddamn, I have a hard time picking a new topic to learn and focusing on it.
>>
>>54454031
learn the C 99 ISO standard
>>
>>54451048
Add the s == 0 in the for loop conditions then use a conditional after to either return 0 or s-t.
>>
>>54453486
the way i see it you have two options to impress him:
1. you can dispaly ALL of the info from his website on your app right now by geting the API calls and whatnot via chrome developer tools and using them in your app.
2. using dummy data you can make it look really pretty.

since he is a business man i would go for #2. he is an "end result" kind of guy, like a consumer. he wants it to look flashy. it is also difficult to get UI "just right" for a client. a lot of them have a hard time describing what they want. i'd say just go for some basic material design type shit. everyone loves that UI. it would give him a good starting point too. just get good animations and other stuff going.

on the other hand, if you go for #1, all you need to tell him is "well i already got more than half the work done, so now we just need to get it to look nice". that will make him REALLY want to do business with you. and at that point you can work on the design closely with him.

good luck man!
>>
a twitter client with electron.atom.io. my mate made the css framework and asked if i wanted to use it. it looks neat. but i had to take some time off to do my dailies on hearthstone, so, not much is done.
>>
>>54453486
use WebView (or the iOS equivalent)?
>>
>>54454024
int avg(int8_t a, int6_t b) {
int16_t ai = a;
int16_t bi = b;
return (int) (ai + bi) / 2;
}
Overflow guaranteed to not occur. Don't worry about truncation, that's a problem with the user.
>>
>>54454024
>he says this may overflow as well

So change it to check for:

#if ((LONG_MAX) > (INT_MAX * 2)) && ((LONG_MIN) < (INT_MIN * 2))
#define AYY long
#elseif ((LLONG_MAX) > (INT_MAX * 2)) && ((LLONG_MIN) < (INT_MIN * 2))
#define AYY long long
#endif
>>
source on original? Google just gives fucking /g/ threads on programming...
>>
>>54454146
he says that int8_t and int16_t are not available in freestanding C and that int6_t doesn't even exist
he also says that this will give incorrect results when a + b > max int but (a+b) / 2 would be in int range

>>54454157
he says that this is pathological code because it relies too much on the c pre-processor and besides being unreadable still doesn't handle every situation
>>
>>54453841
That's what happens when people who unironically like C open their mouths (or bang on their keyboards, as the case may be).
>>
>>54454212
Pathological problems require pathological solutions :^)
>>
>>54454234
I unironically like C though
having arguments about what 'supports' means is just retarded
>>
Hey can anyone help me out?

I'm writing a Web-Crawler where I populate BTrees using RandomAccessFile with word frequencies.

I keep getting "Too many Files open" errors when I run once I get over 100 or so sites.
I can't close the RandomAccessFile because then I can't open it again later, and I need to be able to read from them later.

How should I be going about this?
>>
>>54454212
Take this and fuck off.

int avg(int a, int b)
{
return (a >> 1) + (b >> 1) + (1 & a & b);
}
>>
File: n6iYPAQ.jpg (432KB, 1280x800px) Image search: [Google] [Yandex] [Bing]
n6iYPAQ.jpg
432KB, 1280x800px
>>54449922
The
>implying
can kill flytraps.
>>
>>54454260
he says that this is proprietary code and that if i submit this he'll give me 0 marks for plagirising
>>
>>54454271

>>>>>>> Applel
>>
>>54454276
/*
Copyright (c) 1998, Regents of the University of California
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the University of California, Berkeley nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
int avg(int a, int b)
{
return (a >> 1) + (b >> 1) + (1 & a & b);
}
How about now ?
>>
File: wtf.gif (1021KB, 235x156px) Image search: [Google] [Yandex] [Bing]
wtf.gif
1021KB, 235x156px
>>54454260
Firstly, doesn't work with signed negatives.
Secondly:
1 & a & b
.

Pic related
>>
>>54454303
he says that using bitwise operators for addition and division muddies the conceptual lines of the problem at hand and that, while technically correct, this solution is pathological and an example of wrong-think
>>
>>54454303
That's actually copyrighted code? That little 1 liner? Jesus Christ Berkeley.
>>
>>54454304
That means add 1 if a and b both are odd.
>>
>>54454304
>>54454335
>>54454336
/*
Copyright (c) 1998, Regents of the University of California
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the University of California, Berkeley nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
int avg(int a, int b)
{
return (a / 2) + (b / 2) + (a % 2 + b % 2) / 2;
}
>>
>>54454212
I just thought of this, but I tried it on a few combinations and it seems to work, at least on positive numbers.
>(a & b) + ((a | b) >> 1)
>>
>>54454335
>he says that...

Sounds like a faggot tbqh
>>
>>54454271
Commit suicide immediately macfag
>>
How can you even get away with copyrighting something like that?
>>
>>54453865

int avg(int a, int b) {
return a/2 + b/2 + (a%2 + b%2)/2;
}
>>
>>54454335
I think your professor should kill himself and so should you.
>>
>>54454396
>>54454300
I'm bumming the family computer.
>>
File: halp.gif (2MB, 340x256px) Image search: [Google] [Yandex] [Bing]
halp.gif
2MB, 340x256px
>>54454402
That's how capitalism works, just look at apple attempting to copyright "square icons with rounded corners".
>>
>>54454335
Well I guess you have to humor him because he's in charge of your grade, but this whole "wrong-think" meme can go fuck itself. Programming is a results-driven business. I agree that code readability is important, but if you don't understand how the bit manipulation works on an intuitive level, then you haven't finished learning CS concepts.
>>
Working on a code challenge for a company i'm interviewing for.

I keep feeling like my solution isn't elegant enough despite working fine.
>>
>>54454402
I think if you used that snippet in your own code it would be considered so piddling it wouldn't matter. Copyright covers "substantial" derivative works.
>>
>>54454531
>carmack's reverse.jpg
>>
>>54454548
That was patent law, not copyright law.
>>
>>54454548
It wasn't his though. He doesn't claim copyright over it.
>>
>>54454580
Ah fuck I was thinking of the fast inverse square root function.
>>
>>54454592
He wasn't the first to discover either.
>>
New thread

>>54454616
>>
>>54454518
Sometimes the trick with those code challenges is to ask yourself, "what data structure do they want me to use here?"
>>
>>54454633
Well the data size never changes change, only the data inside the container changes.

I figured just using a simple array would be ok. ArrayList and List would do what I need but if I can just use an Array I save on space and it's a little faster I think?
>>
>>54454613
And apparently he doesn't hold patent over the reverse either.
>>
>>54454361
he says that this is a very good piece of code but that he'll only give me half marks for it because there's a better solution

here's the solution he provided:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#define JAVACODE "public class Average {\n
public static void main(String[] args) {\n
int a = Integer.parseInt(args[0]);\n
int b = Integer.parseInt(args[1]);\n
int c = (a + b)/2;\n
System.exit(c);\n
}\n
}"

#define JAVA_CMDLINE "java Average %d %d"

int main(void) {
FILE *fp = fopen("Average.java", "w+");

if(NULL == fp) {
return -1;
}

size_t javacode_len = strlen(JAVACODE);
fwrite(JAVACODE, javacode_len, 1, fp);
if(ferror(fp)) {
return -1;
}

fclose(fp);

system("javac Average.java");

puts("Please provide two integers to average, separated by a newline:");
int a, b;
scanf("%d", &a);
scanf("%d", &b);

size_t buf_size = strlen(JAVA_CMDLINE) + 1 - 2;
char buf[buf_size];
sprintf(buf, JAVA_CMDLINE, a, b);
char const *aux = buf;

int c = system(aux);

printf("Result of averaging %d and %d: %d\n", a, b, c);

return 0;
}
>>
>>54454708
It's not better in any possible way and there's a buffer overflow in there.
>>
>>54454744
he says that even if it's not a perfect implementation, it's still better than relying on C's type system so it's better
>>
>>54454774
It's still relying on the type system, and you haven't even tried to deny the existence of a security issue in there.
>>
>>54454786
im just relaying what he told me

what are the flaws you see in it?
>>
>>54454806
First, it produce wrong output.
Please provide two integers to average, separated by a newline:
12
32
Result of averaging 12 and 32: 5632

Second, the size allocated in the buf array is smaller than the possible values it can hold, invoking undefined behavior.
>>
>>54454806
Oh, and third, the most obvious bait, is that it relies on having java installed and thus isn't portable.
>>
>>54454806
Besides involving 20x more code, probably having 4000x worse performance, introducing an unnecessary dependency, and being the ridiculous ravings of a professor who both hates and doesn't understand the language he's supposed to be teaching? This is rhetorical code, not useful code. Also, see my earlier comment about the wrongthink meme.
>>
>>54454862
"I don't know what operating system/compiler/etc your friend is using, so I can't comment on why the code doesn't work on his machine, but it works on my machine. However, the code working or not is completely irrelevant: what matters is that you understand the idea behind the snippet.

"Second, the size allocated in the buf array is smaller than the possible values it can hold, invoking undefined behavior"
This is actually a failure of the C language - I have to manually guarantee that the values provided to the %d arguments do not end up blowing the stack due to being too big. Your friend is actually proving me right with this one! :)

"it relies on having java installed and thus isn't portable"
Java is ubiquitous in the desktop/laptop world (and easy enough to install on any platform). This is not a real argument."

this is what he replied to the e-mail i sent him

>>54454886
read above
>>
>>54454271
What libs you running desu?
>>
>>54454989
>This is actually a failure of the C language - I have to manually guarantee that the values provided to the %d arguments do not end up blowing the stack due to being too big.

Well, then it's his fault.
It's like shooting yourself in the foot and blaming guns that it let bullet go.

>Java is ubiquitous in the desktop/laptop world (and easy enough to install on any platform). This is not a real argument."

A code like computing average should be able to run with decent performance on any plateform.
I won't even say more than that since it's blatant bait I shouldn't even waste my time with """your""" """"""professor"""""", who probably never had a real life job.

Why am I even using probably when it's a certainty ?
>>
Is there ever an appropriate time to mix Arrays and non-primitive times in Java? The data set i'm working on sort of requires an Array of some sort and the size is set at the beginning and will never change.

It feels lame to create a two dimensional List and then init it to a specific size with another function.
>>
Guess what I learned in Javascript today:
if(typeof NaN === "number")
console.log("NaN is a number");
>>
>>54450045
What language are you using?
>>
>>54455282
>Not a Number is a number
>>
>>54455394
I think that's gödel but only neckbeards use that
>>
>>54455470
>>54455282
>node is a valuable project which should be taken seriously
>>
>>54454879
Fourth, exit codes can only be relied on for values between 0 and 255 (try it and see)
>>
>>54452275
Why not use workers mate?
Thread replies: 348
Thread images: 32
[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.
If a post contains illegal content, please click on its [Report] button and follow the instructions.
This is a 4chan archive - all of the content originated from them. If you need information for a Poster - you need to contact them.
This website shows only archived content and is not affiliated with 4chan in any way.
If you like this website please support us by donating with Bitcoin at 1XVgDnu36zCj97gLdeSwHMdiJaBkqhtMK