[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 326
Thread images: 34

File: cool kids club_.png (327KB, 1158x980px) Image search: [Google]
cool kids club_.png
327KB, 1158x980px
What are you working on, /g/?

Old thread: >>59327254
>>
>>59332981
whatever, this thread seems nicer
>>
File: Capture.jpg (21KB, 851x49px) Image search: [Google]
Capture.jpg
21KB, 851x49px
Need help plox
>>
>created way before bump limit
No.

ACTUAL NEW THREAD:
>>59333003
>>59333003
>>59333003
>>
assembly question

i can't seem to be able to find an example of x86 assembly (preferrably ATT syntax) of a program using command line arguments

i just need to know where I access the number of arguments(ie argc) and where i access the pointer to the arguments (ie char** argv)
and where i access the name of the program

i should be able to just use ebp somehow, but i don't know where ebp points to in the beginning and can't find info

halp
>>
>>59333038
>created way before bump limit
Not true.
>>
>>59333067
It is true, you made this at 309
>>
>>59333031
haram
>>
>>59333057
Chart doesn't seem too far off, but I do question it a bit.

Namely, the fact that Javascript isn't higher.
>>
File: SS_002.png (662KB, 667x836px) Image search: [Google]
SS_002.png
662KB, 667x836px
Can someone help me with this, this is what happens when i try to start downloading from my app
>>
>>59333057
Most of the job listings I see for C# say ".NET Developer".
I'd be curious as to what that looks like if you take that into account.
Probably tons of javascript jobs left off due to them just saying "website developer".
>>
>>59333116
>his is what happens when i try to start downloading from my app
What do you think should happen instead?
>>
>>59333099
>>59333119
He's clearly making fun of these popularity charts.
>>
>>59333131
It is not downloading file anon, it add torrent and remove it for unknown reason
>>
>>59333031
sauce?
>>
>>59332981
That multiple selection poll is just woefully inadequate for measuring anything. Speaks for how retarded the person who made it is.
>>
>>59333035
a[n]>a[n-1]: add to ms_arr; inc n;
else: inc n;
Repeat for various starting positions: start at n=0,n=1,etc... check size of ms_arr;
>>
>>59333200
wouldn't that find only consecutive numbers?
>>
>>59333206
Ahhh, yes, thanks... I mean I wouldn't do that, of course, but it's good to know.
>>
>>59333221
Yes. He misunderstood the problem.
>>
>>59333057
My goal in life is to learn the top 3 reasonably well + Python. Still haven't gotten into C# though.
>>
>>59333198
I believe it is specifically made to get a rise from reasonable people like you.
>>
>>59333242
Could you write those 2 for loops in code, i'm not really sure if you're correct
>>
>use references for everything in c++
>feel like a fucking god
>>
>old thread got deleted
what a radical solution
>>
I'm sick of being at the mercy of the scummy dev's who make a living off of the play store.
I want to make my own android apps, where's a good place to start?

I already know Java, just never tried to make anything for another device.
>>
File: 1489154047193.png (47KB, 931x486px) Image search: [Google]
1489154047193.png
47KB, 931x486px
>>59333276
The top 3 being Java, C++ and C#.
>>
>>59333332
Install Android Studio and fill in the gaps
>>
https://blogs.msdn.microsoft.com/dotnet/2017/03/09/new-features-in-c-7-0/

switch(shape)
{
case Circle c:
WriteLine($"circle with radius {c.Radius}");
break;
case Rectangle s when (s.Length == s.Height):
WriteLine($"{s.Length} x {s.Height} square");
break;
case Rectangle r:
WriteLine($"{r.Length} x {r.Height} rectangle");
break;
default:
WriteLine("<unknown shape>");
break;
case null:
throw new ArgumentNullException(nameof(shape));
}


(string first, string middle, string last) LookupName(long id) // tuple return type
{
// retrieve first, middle and last from data storage
// ...

return (first, middle, last); // tuple literal
}

// ...

var names = LookupName(id);
WriteLine($"found {names.first} {names.last}.");


public int Fibonacci(int x)
{
if (x < 0) throw new ArgumentException("Less negativity please!", nameof(x));
return Fib(x).current;

(int current, int previous) Fib(int i)
{
if (i == 0) return (1, 0);
var (p, pp) = Fib(i - 1);
return (p + pp, p);
}
}
>>
>ŧfw your hardcore number crunching pushes the java GC to the limit
i-i dont want to learn C++ just for this
>>
>>59332981
>What are you working on, /g/?
Still working on Hydrus tag repository scraper. Writing parsers for 50 thousand levels of nested tuples.
>>
looks like mod finally arrived with banhammers
>>
File: 1452715120528.png (651KB, 561x800px) Image search: [Google]
1452715120528.png
651KB, 561x800px
Do you have an anime picture of your favorite programming language?
>>
Fuck the C haters
C ftw
>>
>>59333116
you wrote the piece of shit. you should know
>>
File: 1442750574870.png (1MB, 1200x1800px) Image search: [Google]
1442750574870.png
1MB, 1200x1800px
C is a classy mature woman.
What's your favorite?
>>
>>59333471
C++ is best girl, but the language is shit.
>>
>>59333368
>Writing parsers for 50 thousand levels of nested tuples.
why does it matter how nested the tuples are

it's a tree either way
>>
>>59333487
C++ a slut, she takes whatever hot feature members of the standard committee want to put in her.

C is far more conservative.
>>
>>59333471
PHP is cutest.
>>
File: anime.png (786KB, 1000x1300px) Image search: [Google]
anime.png
786KB, 1000x1300px
>>59333471
Haskell, because she's pure
>>
>>59333471
in python you get to pet the snake
>>
Neon Genesis Evangelion: C
Serial Experiment Lain: Lisp
>>
>>59333471
C++ is the sluttiest
>>
>>59333637
anime : trash
>>
>>59333505
Because it's not a tree, it's a structure of multi-level nested objects without keys mixed with tuple arrays. To make it worse, it's full of redundant data, that can be easily inferred. Here's a truncated sample: https://hastebin.com/uheqodeyej.json
>>
>>59333637
Serial Experiment Lain: Python
Flip Flappers: Haskell
>>
File: 1421164417027.png (342KB, 714x738px) Image search: [Google]
1421164417027.png
342KB, 714x738px
>>59333648
Anime website
>>
>>59333658
Python was barely known at the time of Serial Experiment Lain
>>
>>59333035
first sort the array, then do what >>59333200
said
>>
>>59333648
opinion: discarded
>>
>>59333658
Lain is often seen programming in Lisp
>>
>>59333671
>>59333693
Lain is the entry level bro anime of deep shows like Python, Flip Flappers is the apex like Haskell.
>>
>>59333652
so it's a complex tree without parent pointers
>>
File: hqdefault (4).jpg (18KB, 480x360px) Image search: [Google]
hqdefault (4).jpg
18KB, 480x360px
Asm is Texhnolyze
>>
>>59333729
My point it that it does not need to be a complex tree. This API would have been far easier to use, if it returned a struct with 2-3 tuple/struct array fields.
>>
>>59333637
Paranoia agent: brainfuck
>>
writing a compiler
it will have 1 (one) datatype a 32bit signed int
it will also have pointers, 32bit ints also

if you want to pass a char to a function, you pass an int from 0 to 256

if you want strings, well, you use arrays of ints and utilize bit operations to fit 4 bytes/int

this scheme is feasible write, no problem to write a "standard" IO library for such a language
>>
File: king autists.jpg (40KB, 620x413px) Image search: [Google]
king autists.jpg
40KB, 620x413px
>>59333332
>blaming devs when devs have to pay to get in
>>
>>59333832
Are you making Java?
>>
>>59333832
>char
>0 to 256
>256

What the fuck?
>>
>>59333337
> That Java dominance
Here's it's 50/50 .Net and Java stacks.
Makes for much funnier banter at meet-ups etc.

"Web Dev" is also up there.
>>
>>59333870
no
the thing that will be the syntax looks like this currently, the language will be prettier but transformed to this

this takes two arguments, a and b
has 0 local storage(for local variables)
and returns the bigger one
in the language everything is an expression, so like rust

compile_function("max", [["a", "1"], ["b", "1"]],
[],
["if", [">", "a", "b"], "a", "b"])

>>59333901
i will use an ascii table
actually 0 to 255, obviously
>>
>>59333471
ActionScript looks like artwork from Rustle.
>>
>>59333676
If you sort it you fuck up everything mate
>>
>>59332981
>writing in a typesafe language in an ide on a mac
welp
>>
What do you guys think of ruby?
>>
>>59333957
I don't like tripfags in overall.
>>
>>59333957
Her favourite language is shit
>>
>>59333923
.type max, @function
max:
pushl %ebp
movl %esp, %ebp
movl 8(%ebp), %eax
pushl %eax
popl %eax
neg %eax
pushl %eax
movl 12(%ebp), %eax
pushl %eax
popl %eax
neg %eax
pushl %eax
popl %ebx
popl %eax
cmpl %ebx, %eax
pushfl
popl %eax
movl %eax, %ebx
shrl $7, %eax
and $1, %eax
shrl $11, %ebx
and $1, %ebx
xor %eax, %ebx
pushl %ebx
popl %eax
cmpl $0, %eax
je else_clause_max_0
movl 8(%ebp), %eax
pushl %eax
jmp skip_else_clause_max_0
else_clause_max_0:
movl 12(%ebp), %eax
pushl %eax
skip_else_clause_max_0:
popl %eax
movl %ebp, %esp
popl %ebp
ret

here's the assembly
it has tons of "push %eax, pop %eax", but those are VERY easily optimized away later

i honestly can't remember what it does since i wrote most of the code months ago with 0 comments

but it's processing the "if" expression

r8
>>
>>59333060
microsoft donated the source code of DOS 1.0 to a museum, it's available for download and study. Check that.
>>
>>59332981
// If submit with POST
if ($_POST) {
// Test for nothing entered in field
if ($_POST['firstName'] == "") {
$firstNameErr = "Error - you must fill in a first name";
$dataValid = false;
}
if ($_POST['lastName'] == "") {
$lastNameErr = "Error - you must fill in a last name";
$dataValid = false;
}
}
// If the submit button was pressed and something was entered in both fields, process data
// (we just print a mesg)
if ($_POST && $dataValid) {
?>
Data is valid!
<?php
// If no submit or data is invalid, print form, repopulating fields and printing err mesgs
} else {
?> //FOLLOWING NOT IN PHP TAGS , WHAT IS GOING ON??
<form method="post" action="">
First name:<input type="text" name=firstName value="<?php if (isset($_POST['firstName'])) echo $_POST['firstName']; ?>"><?php echo $firstNameErr;?>
<br/>
Last name:<input type="text" name=lastName value="<?php if (isset($_POST['lastName'])) echo $_POST['lastName']; ?>"><?php echo $lastNameErr; ?>
<br />
<input type="submit">
</form>
<?php


why is some text not in php tags when this is a php file?
what happens to the text that is not inside php tags
>>
>>59333351
> out variables
Just fucking why.

Is there anything, anything at all, that these fuckers will not add to their language?

> touples
I'm kind of on the fence about this.
On the one hand they make some common use cases simpler. On the other hand, for production code that's going in a large enterprise system, you really should use separate classes for this, so that it's always semantically clear what you're getting in return.

Basically, instead of
 return (4, 5);

you actually should return
return new Coordinates(4,5);


This does requires you to make a whole new class, but C# has decorators to make that shit fucking obvious.

And if you really need the speed, you have all sorts of disgusting tricks to do it fast regardless.

For quick and dirty exploratory code though, it seems really fucking nice.

>>59333356
> hardcore number crunching
> pushes GC to the limit
Stop generating garbage as much as possible.

>>59333870
Java has an unsigned int type.
It also has 8, 16, 32 and 64 bit signed int types, floats and doubles.
>>
>>59334025
this is in reference to my apache server and php module
>>
>>59333964
I was thinking of the language.
>>
>>59333471
JavaScript isn't ADHD enough. I guess this was made back when the JS community was content with jQuery.

Also,
>best girl being worst language
Why is this allowed?
>>
>>59333035
Try some implementation of Dijkstra's algorithm, searching for the longest path (in terms of number of nodes).
>>
>>59333356
Learn how GC works. Reuse objects if you have to. Look into object pools.

Or just don't use Java for hardcore number crunching. It's like trying to use word when you really need libreoffice calc.
>>
>>59334084
dijkstra is a shortest path algorithm and you can't use it to find longest paths even if you flip the weights to be negative
>>
genetic evolution of fuzzy rules
please help they converge to quickly (probably to few rules and inputs)
>>
File: 1488993470343.png (405KB, 630x630px) Image search: [Google]
1488993470343.png
405KB, 630x630px
>>59333337
>mfw nobody wants a Ada developer
>>
>>59333035
>mfw no one on /g/ provided clear answer for this shitty problem for 2 days already
>>
>>59334289
I can't think of anything that isn't bruteforce big-O(n!)
>>
>>59334289
>clear answer
There has been plenty of clear answers. But nobody can explain well enough for a retard to get it.
>>
>>59332981
I'm learning Python and I don't know why
>>
>>59334361
>tfw reading Maximum length sequence wiki
>tfw don't get it
>tfw must mean I'm retarded
>tfw retarded
>>
>>59334391
My condolences. But it's not that bad. You can become a prostitute.
>>
>>59334407
Well I'm a JS dev just visiting from /wdg/.. I come here when I wanna feel dumb.
>>
>>59334437
>JS dev
So you're already a prostitute..
>>
>>59334437
>js dev
Top kek!

So you copypaste from stack overflow and glue frameworks together with spaghetti code

Fuck web """devs'""
>>
Is it smart to run a tor exit node on your computer for plausible deniability about what you're searching for online?
>>
File: 54c86e3ebd-1486689444701.jpg (67KB, 528x600px) Image search: [Google]
54c86e3ebd-1486689444701.jpg
67KB, 528x600px
Hey /dpt/ do you guys know if theres a VM that allows you to see its memory?
Am writing a small os in assembly and its hell to write without knowing whats going on in the stack.
>>
>>59333035
typedef struct list
{
int v;
struct list *n;
} list;

/* O(n^2) */
int findSequence( int *seq, int n, int **res )
{
int len = 1, *lengths, ind;
list *l;

allocArray(&lengths, n);
l = malloc(sizeof(list) * n);
memset(l, 0, sizeof(list) * n);

for (int i = 0; i < n; i++)
l[i].v = seq[i];

for (int i = n - 1; i >= 0; i--)
for (int j = i; j < n; j++)
if (l[j].v > l[i].v && lengths[j] >= lengths[i])
{
lengths[i] = lengths[j] + 1;
l[i].n = &l[j];
}

len = maxElement(lengths, n, &ind);

allocArray(res, len);

list *s = &l[ind];

for (int i = 0; i <= len; i++)
{
(*res)[i] = s->v;
s = s->n;
}

free(l);
free(lengths);

return len;
}

int main( void )
{
int *a = 0, n = 0, len = -1, *res = 0;

if (readSequence("muhSequence.2", &a, &n))
return EXIT_FAILURE;

len = findSequence(a, n, &res);

for (int i = 0; i <= len; i++)
{
printf("%i ", res[i]);
}

free(res);
free(a);

return EXIT_SUCCESS;
}
>>
>>59334478
>>>/g/sqt
I'd probably not ask here, but rather look at court cases similar to those you expect.

And I certainly wouldn't say that I'm planning to employ tactics to counter the judicial system on 4chan.
>>
>>59334494
Just implement a hex dump function.
>>
>>59333035
Make a 'sequence' array, initially empty.

Get a number from the input array, placing into every sequence into the sequence array where it is larger than the last element. Otherwise, make a new sequence in the array and make that the initial element.

Continue for all the numbers in the input array. Once completed, find the sequence in the sequence array with the maximum length.

pseudo-code
for num in input
for sequence in sequences
if num > sequence[end]
sequence[end+1] = num

print(max(filter(\x: len(x), sequences)))


O(n) time, O(n^2) space.
>>
>>59334478
I feel like your ISP would shut you down for all the sketchy plaintext stuff going on
>>
>>59334441
>>59334457
>spaghetti code
It's getting better with frameworks that enforce better project structure.

>So you're already a prostitute
Yes, I'm a total whore for js

So how long have you guys been devs? What do you do? I'm wondering how different it is from my job
>>
>>59334513
>So how long have you guys been devs?
You think people here have jobs? Hah, silly /wdg/.
>>
>>59334502

Thats the thing I need to see it in real time because I keep getting a bug in qemu and virtualbox which only happens 50% of the time when testing on real hardware, its fucking bizarre.
>>
>>59334504
I fucked up the pseudo-code. Forgot the bit to place the number in a new sequence if it couldn't put it in another sequence.

for num in input
placed = false
for sequence in sequences
if num > sequence[end]
placed = true
sequence[end+1] = num
if not placed
sequences[end+1] = [num]

print(max(filter(\x: len(x), sequences)))
>>
>>59334533
never bring python pseudocode here again
>>
In Javascript, is there a function that takes multiple arrays and combines them into one big array?
>>
>>59334494
Use a debugger.
>>
>>59334562
It's actually closer to MATLAB or Lua if you look at it. Besides the lambda of course.
>>
>>59334571
Array.concat

Look it up on mdn
>>
>>59334533
 {9, 6, 2, 7, 4, 7, 6, 5, 8, 4} 


 sequences:
() -> ((9)) -> ((9) (6)) -> ((9) (6) (2)) -> ((9) (6 7) (2 7))


we already lost (2 4 6 8)
>>
>>59334504
>>59334533
O(n^2) time, consider {5,4,3,2,1}
>>
>>59333035
You can do it in O(n) space. Keep a solution array of tuples/length 2 lists ect. From the back of the list, walk forward. For each item, search backward and find the maximum subarray length based on the current value, as well as the maximum sub array length index. Keep track of index with max 'length' as you walk backward to the front of the input, the just walk down the indices you collected for your max length subarray.
>>
>>59334642
What a fail
>>
>>59334651
It is O(n^2), but this
>>59334642

Anyway, your example would contain only
[[5], [4], [3], [2], [1]] because nothing is sequentially larger.

But yes, my off-the-cuff response wasn't correct. Oh well.
>>
>>59334685
>O(n)

no way son
>>
>>59334685
kinda did it here, yeah >>59334497
looks like O(n^2) time and O(n) space

wiki says that The Donald solved it in O(nlogn)
>>
File: problemwithrecursion.png (22KB, 683x462px) Image search: [Google]
problemwithrecursion.png
22KB, 683x462px
I fucking hate recursion. I can't follow wtf is going on. I'm trying to reverse a string with only the lower case letters in tact. Idk how to swap with last in the string cause not provided with the length.
>>
>>59334837
if (*str == '\0')
{
str = str+1;
}

>if the end of the string, keep on going
>>
>>59334837
>I fucking hate recursion
Good.

Recursion is a crutch used by bad programmers that can't properly form an iterative solution.
>>
I'm trying to get my head around fuzzy logic, seems theres no one in the field that can explain it concisely without a load of fucking bullshit.

anyone know of any FL texts that aren't absolute fucking trash?
>>
File: ree.jpg (111KB, 1058x705px) Image search: [Google]
ree.jpg
111KB, 1058x705px
>>59334860
>
if (*str == '\0')
{
str = str+1;
}
>>
>>59334862
Excellent bait
>>
>>59334884
>using a meme this literally
poor form
>>
>>59334874
Fuzzy logic, at it's heart, is extremely basic.

At the risk of oversimplifying:
Rather than saying it's "old" or "new", say how old it is. "Very old." "Somewhat new." Take these things and quantify them somehow in a meaningful way and make decisions based on this.
>>
>>59333035
The example is wrong because it could be 2,4,7,8 as well as 2,4,6,8.

>it says maximum so it means sum.

No it doesn't. It says maximal sequence, which could mean length.
>>
>>59334025
the non PHP text is just html
>>59334494
QEMU has this functionality IIRC. might be with some remote debug feature can't remember the details
>>59334862
lol
>>
>>59334897
i get that my dude, and all texts do make that very clear, its just when it comes to the fuzzy implication and defuzzification stages the writer's minds turn to sludge and they either gloss over details entirely or overload the reader with information
>>
>>59334874
>I'm trying to get my head around fuzzy logic

pic related
>>
>>59334897
What is fuzzy logic used in? GC?
>>
>>59334911
You're right, this example has multiple solutions and your solution would be found first if it starts from left to right
>>
>>59334874
>>59334897
What is the difference between fuzzy logic and just a computation with numbers in a specific range?

If there is a case where I say, well I'm only 76% true that this is the case, why don't they just call it computation with floats?
>>
>>59334939
s/true/sure/g
>>
>>59334874
Foundations Of Soft Case-based Reasoning - SANKAR K. PAL

>>59334939
They needed a buzzword to sell washing machines, its basically doing neural net encoding but without the neural net.
>>
>>59334939
its more for translating human intuition to something a computer can handle. like how hard you press brakes based on your speed.
>>
2 points :/
Hate Apple, Hate Ubuntu
>>
>>59334957
i.e. are you going "fast" or "really fast" or "slow", how hard do you press? "EXTREME", "medium", "little" and so on. its best used when you dont fully understand the model used
>>
If I want to learn about web development, backend and frontend what should I learn?

Should I go with python/django or Node/reactJS?
>>
>>59333060
It's just passed in on the stack. It's pretty similar to getting the variables passed to a regular function.
>>
>>59335069
>>>/g/wdg
>>
>>59333060
I'm pretty sure that the loader places the values in the locations pointed to by argc and argv when the program loads. Just define them and the loader does the rest.
>>
>>59335149
nvm this.

https://godbolt.org/g/1zFPa9

comes in as first and second arguments to the main func. lol.
>>
>>59334874
Fuck all that noise. Fuzzy logic is like this: You take a set of [0, 1) inputs, and use the defuzzification method to find their location on the control surface, which is the set of rules you've laid out previously. For a two-input system, this looks like a 2D landscape with hills and valleys and shit. With 3 inputs, it looks like a 3D landscape, high and low but also wide and also tall.

For example,
Temperature: 0, .33, .66, 1 (cold, cool, warm, hot)
Speed: 0, .5, 1. (off, low, max)

When you pass in two values, it'll find how close those inputs are to the current rules, and then tell you which rules it's falling under: so you give it Temp .45, Speed .45, and based on the defuzzification method you use, it'll tell you which of those above values will fire. In this case, it'd be the second rule in Temperature and the second rule in Speed that fire.

If you get super complex you assign values to each pair of rules, and use the output values as your next input in some sort of controller.
>>
>>59333060
Depends on the abi.
On amd64 sysv (i.e linux, bsd, mac) rsp points to argc and rsp+8 to argv on entry point.
>>
>>59334874
>>59335189
Folks hate on python (they're fucking idiots), but you should check out skfuzzy: http://pythonhosted.org/scikit-fuzzy/ it'll show you everything you need to get an understanding of how it works. i don't like the way it's done, but it's clear and obvious and will teach you the principles.
>>
Can someone explain how php sessions work, particularly through a proxy, and are they completely secure? The W3S site says they leave a key on your computer, yet they are different from cookies? Just can't wrap my tiny brain round it.
>>
File: 1484332469273.jpg (32KB, 412x430px) Image search: [Google]
1484332469273.jpg
32KB, 412x430px
>>59333035
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;

namespace MaximalSequenceOfIncreasingElements {
public class Program {
public static List<List<int>> longest = new List<List<int>>();

public static void Main(string[] args) {
Debug.Indent();

var elements = new List<int>() { 9, 6, 2, 7, 4, 7, 6, 5, 8, 4 };

LongestSequences(elements);
Print(longest);
}

public static void LongestSequences(List<int> elements) {
longest.Add(new List<int>());

for (var n = 0; n < elements.Count; n++) {
LongestSequences(new List<int>(), elements.Skip(n).ToList());
}
}

public static void LongestSequences(List<int> taken, List<int> remaining) {
var combined = taken.Concat(remaining).ToList();

if (Sorted(combined) && combined.Count >= longest.Last().Count) {
if (combined.Count > longest.Last().Count) {
longest.Clear();
}
longest.Add(combined);
}

for (var n = 0; n < remaining.Count; n++) {
LongestSequences(taken.Concat(remaining.Take(1)).ToList(), remaining.Skip(n + 1).ToList());
}
}

public static bool Sorted(List<int> elements) {
for(var n = 0; n < elements.Count - 1; n++) {
if(elements[n] >= elements[n + 1]) {
return false;
}
}
return true;
}

public static void Print(List<List<int>> elements) {
foreach (var element in elements) {
Print(element);
}
}

public static void Print(List<int> elements) {
foreach (var element in elements) {
Debug.Write(" ");
Debug.Write(element);
}
Debug.WriteLine("");
}
}
}


Ugly, slow, but works.
>>
I've been learning about Selection sort algorithm and every single example i've seen uses some variable when they need to swap the numbers

Why no one does something simple as this:

            for (int i = 0; i < arr.Length - 1; i++)
{
for (int j = i+1; j < arr.Length; j++)
{
if (arr[j] < arr[i])
{
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
>>
>>59335310
Emphasis on ugly. gj though
>>
>>59335310
EWWWWWWWWW

there has to be cleaner solution
>>
>>59335359
Can you give an example of how others are doing it?

>inb4 python arr[i], arr[j] = arr[j], arr[i]
>>
>>59335310
wtf is this? c#?
kys my man
>>
>>59335388
for example this
public void selectSort(int [] arr)
{
//pos_min is short for position of min
int pos_min,temp;

for (int i=0; i < arr.Length-1; i++)
{
pos_min = i;//set pos_min to the current index of array

for (int j=i+1; j < arr.Length; j++)
{
if (arr[j] < arr[pos_min])
{
//pos_min will keep track of the index that min is in, this is needed when a swap happens
pos_min = j;
}
}

//if pos_min no longer equals i than a smaller value must have been found, so a swap must occur
if (pos_min != i)
{
temp = arr[i];
arr[i] = arr[pos_min];
arr[pos_min] = temp;
}
}
}


or this

        for (int j = 0; j < array_size - 1; j++)
{
min_key = j;

for (int k = j + 1; k < array_size; k++)
{
if (array[k] < array[min_key])
{
min_key = k;
}
}

tmp = array[min_key];
array[min_key] = array[j];
array[j] = tmp;
}
>>
Why can't I seem to overload the "<<" operator on my struct?

#include <iostream>
#include <set>

struct Index
{
int xInd, yInd;
Index(int x, int y)
{
this->xInd = x;
this-> yInd = y;
}

bool operator<(const Index& rhs)
{
return (this->xInd < rhs.xInd);
}
std::ostream& operator<<(std::ostream& out)
{
out << "( " << this->xInd << ", " << this->yInd << ")\n";
return out;
}

};

int main()
{
Index i(5, 5);
std::cout << &i << std::endl;
return 0;
}


When I compile this, I get the following error:
Invalid operands to binary expression ('const Index' and 'const Index')


in the file
/usr/include/c++/v1/__functional_base:63:21

I have no idea what's going on
>>
>>59335265
Which tutorial on the example page gives a good overview of Fuzzy Logic? All of them? I wanna check it out.
>>
>>59335372
I'm listening.
>>
>>59335477
not op but looking through, https://pythonhosted.org/scikit-fuzzy/userguide/fuzzy_control_primer.html seems good
>>
>>59335265
thanks friendo, some of the things here look good. presumably thats because they're demonstrating them with code along the way and it forces correct descriptions of things
>>
>>59335539
I wish i knew
>>
>>59335563
>>59335549
>>59335477
Those are some good pages, but look out at the end of the control primer page, cuz it gives you the "old api" tutorial, and the "new api" tutorial is much better: http://pythonhosted.org/scikit-fuzzy/auto_examples/plot_tipping_problem_newapi.html

The underlying idea is you're finding out "how much" of a given rule an input falls under, and then computing what the output should be based on the inputs. That's the "fuzzy" part. So at the end of the tipping tutorial, it's saying "because the service was VERY GOOD (9.8), we're going lend significantly more weight to it's value than the quality, which was only slightly above average (6.5)."

This is what I meant when I said "control surface": http://pythonhosted.org/scikit-fuzzy/auto_examples/plot_control_system_advanced.html
>>
>>59335606
Get to fucking work, boy.
>>
>>59335539
//read data
int n = int.Parse(Console.ReadLine());
int[] arrayInt = new int[n];
for (int i = 0; i < n; i++)
{
arrayInt[i] = int.Parse(Console.ReadLine());
}
//find longest rising sequence
int[] sequenceLength = new int[n];
int[] previousInd = new int[n];
int bestEndInd = 0;
int maxCount = 0;
for (int i = 0; i < arrayInt.Length; i++)
{
int maxBefore = 0;
for (int j = 0; j < i; j++)
{
if (arrayInt[j] < arrayInt[i] && sequenceLength[j] > maxBefore)
{
maxBefore = sequenceLength[j];
previousInd[i] = j;
}
}
sequenceLength[i] = maxBefore + 1;
if (sequenceLength[i] > maxCount)
{
maxCount++;
bestEndInd = i;
}
}
//print
int arrayIntInd = bestEndInd;
int[] bestSequence = new int[maxCount];
for (int i = 0; i < maxCount; i++)
{
bestSequence[i] = arrayInt[arrayIntInd];
arrayIntInd = previousInd[arrayIntInd];
}
for (int i = 0; i < maxCount; i++)
{
Console.Write(bestSequence[maxCount - i - 1]);
if (i < maxCount - 1)
{
Console.Write(" ");
}
}
>>
http://www.apple.com/uk/education/everyone-can-code/
Reminder everyone can code, if you don't think so then you're a white male biggot.
>>
>>59335676
>Anyone can code!
Not with those CS and math course dropout rates.
>>
>>59335655
This only prints a single array. What if there are multiple solutions?
>>
>>59335359
https://en.wikipedia.org/wiki/XOR_swap_algorithm
>>
>>59335721
It didn't ask for multiple solutions
>>
>>59335676
>everyone can code
I find it slightly racist that they put a black kid there. But I dunno maybe that's not racist, I'm sure they wouldn't be racist. There's no white people in the picture.
I'm very confused.
>>
>>59335655
There's no way this works. What's the output for [1,9,2,3,4,5,6,7]?
>>
>>59335750
Thanks for coming. Don't call us, we'll call you.
>>
>>59335774
Actually it's UK people of modern times.
>>
>>59335778
It does work. Output is 1 2 3 4 5 6 7, just as you would expect.
>>
>>59335801
I don't think that makes any difference.
>>
>>59333035

What kind of shit English is this?
>>
im trying to loop through an array of JSON objects

i'm getting results but they're being repeated too many times. I should be getting only 3 results instead i get 100+. I even tested the query im using in the command line and it worked, so i know the query is fine.

var data = JSON.parse(this.responseText);
for (x in data)
{
for (i in data[x])
{
document.getElementById("resultList").insertAdjacentHTML("beforeend", data[x].Name + "<br />");
}
}


what went wrong?
>>
>>59335778
ayy it works
>>
>>59333035
/g/ butthurt: the problem
>>
File: 1474325720217.jpg (39KB, 367x458px) Image search: [Google]
1474325720217.jpg
39KB, 367x458px
memesnek is the most worstest of popular languages around
meaningful whitespace was a mistake
>>
File: image.jpg (225KB, 800x600px) Image search: [Google]
image.jpg
225KB, 800x600px
Write a function that accepts an array of 10 integers (between 0 and 9), that returns a string of those numbers in the form of a phone number.

Example:
createPhoneNumber([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) // => returns "(123) 456-7890"


My attempt:
function createPhoneNumber(numbers){
let str = "";
for (var i=0;i<numbers.length;i++) {
if(numbers.indexOf(i) === 0) {
str += "(";
}
if(numbers.indexOf(i) === 3) {
str += ") ";
}
if(numbers.indexOf(i) === 6) {
str += "-";
}
str += numbers[i];
}
return str;
}


Produces error:
Expected: '(123) 456-7890', instead got: '1(234) 567-890'


Why is this the case when I did:
if(numbers.indexOf(i) === 0) {
str += "(";
}


Inb4 homework, it's just a challenge I'm working on at codewars
>>
Modules are type classes
>>
>>59335933
>numbers.indexOf()
what the fuck are you doing
>>
File: miyako_code.png (2MB, 1280x720px) Image search: [Google]
miyako_code.png
2MB, 1280x720px
>>59333426
This was made back when I only knew C++, Python and Mathematica.
>>
>>59335820
Maybe try of instead of in.
>>
>>59335933
let createPhoneNumber = n => `(${n.slice(0,3).join('')}) ${n.slice(3,6).join('')}-${n.slice(6).join('')}`
>>
File: image.jpg (28KB, 380x380px) Image search: [Google]
image.jpg
28KB, 380x380px
>>59335986
i-it should probably be a foreach r-right?
>>
Friendly reminder that ownership is monadic :^)
>>
>>59335933
In C this would just be
void createPhoneNumber(int* numbers){
printf("(%d%d%d) %d%d%d-%d%d%d",
numbers[0],numbers[1],numbers[2],
numbers[3],numbers[4],numbers[5],
numbers[6],numbers[7], numbers[8],numbers[9]);
//altenatvely use sprintf
}


But if this were C you'd probably be given a different assignment. C makes programming too easy for class in many cases.

(most languages replicate sprintf or printf in some form, unless it's forbidden it's wise to use formatting functions for string processing)
>>
>>59336014
Less powerful than that. Everything you can do with substructural types, you can do with a spin on good old algebraic effects.
>>
>>59336024
>missed a %d
>get a runtime error.
Well shit.
It's
"(%d%d%d) %d%d%d-%d%d%d%d"

As the format string obviously.
>>
>>59336013
numbers.indexOf(i) will give you the index of i. So when i == 0 numbers.indexOf(i) == 9.
You want if (i == 0)
>>
>>59336006

i figured out. I actually started with that code from a stackoverflow answer. But he was retarded since you don't need nested for loops to loop through an array of objects.

correct code is:

for (x in data)
{
document.getElementById("resultList").insertAdjacentHTML("beforeend", data[x].Name + "<br />");
}
>>
>>59336054
yeah my whole method was wrong i realize i should have went with a foreach

>>59336010
this anon thinks outside the box though
t-thanks senpai
>>
>>59336076
for loop is fine here because you want the index in addtion to the element. I personally dont like using indexOf at all because it has strange results when a number appears multiple times
>>
>>59333693
Really? I don't remember seeing that.
>>
>>59335933
In [5]: alist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]

In [6]: result = "(123) 456-7890"

In [7]: def create(l):
...: return '({}{}{}) {}{}{}-{}{}{}{}'.format(*l)
...:

In [8]: create(alist)
Out[8]: '(123) 456-7890'

In [9]: def create(l):
...: builder = ''
...: for idx, num in enumerate(l):
...: if idx == 0:
...: builder += '('
...: elif idx == 3:
...: builder += ') '
...: elif idx == 6:
...: builder += '-'
...: builder += str(num)
...: return builder
...:

In [10]: create(alist)
Out[10]: '(123) 456-7890'
>>
>>59336097
>strange
What do you mean? Is it non-deterministic?
>>
>>59336099
Lain often evades memory
>>
>>59336097
>strange results
bruh, it's not strange, it's simple: it returns the first index. that's it. don't use indexof if you could possibly have multiple elements of the same value, unless you absolutely want the first.
>>
>>59336104
typically its the index first element but it varies between languages so I always need to look it up and sometimes i want the second element. plus its a somewhat costly operation so its best to avoid it
>>
Is it possible to receive calls and sms messages on a pc with some sort of a usb sim card reader?
>>
>>59336188
There's such a thing on aliexpres for 2.5$.
"USB SIM Card Reader Adapter Mobile Phone SMS Edit Copy Backup GSM CDMA Blue"
>>
>>59336188
>>>/g/sqt
>>
>>59336223
>backup
I don't give a shit about the data sim card holds.
I want to programmatically handle sms and calls live.
>>
>>59335462
operator<< should take an ostream on the left hand side and your own type on the right. right now you got it the wrong way around.
try this:
friend auto& operator<<(std::ostream& out, const Index& i) const
{
out << "( " << i.xInd << ", " << i.yInd << ")";
return out;
}

needs to be "friend" since it's not a member function. but you can still define it inside your struct.

also don't put a newline in your operator<< for no reason.

also
std::cout << &i << std::endl;

you're only printing the address of your struct there.
>>
>>59334264
Ada's not good for Pajeet. Pajeet finds it difficult to use a real type system.
>>
>>59336386
>real type system
Ada can do barely any checking statically, though.
>>
>>59336484
That's not what a compiler is for
>>
>>59336520
Years of type theory research disagree with you.
>>
>>59335462
by the way there's no reason to use "this->" everywhere, unless you're inheriting from some other type. and your constructor can be simplified by avoiding assignment:
int xInd, yInd;
Index(int x, int y): xInd(x), yInd(y) { }

doesn't really matter for plain integers, but you should get used to using this method. when initialization order matters, or your variables' types don't have a default constructor, or assignment is expensive (involves copying), this is the only way to do it.
>>
>>59336522
It's what analysis tools are for.
>>
>>59336542
Why have a separate analysis tool when the compiler can do it and use the increased information to perform more optimizations?
>>
>>59336551
Cause the compiler already assumes the best. The analysis is so you can trust the compilers choices.
>>
>>59336590
In order for that to be practical you need to have an intermediate language that has all the annotation capabilities of the typed language (e.g. a language without linear types but with restrict), and the analysis tools should convert from one to the other.

Why bother when you can just do it all with one language, one type system, and one tool?
>>
>>59336590
That's the dumbest shit I've ever heard.
>>
>>59336619
No one's stopping you to do that with any language. Why do you think that's language specific for some reason?
>>
>>59336652
The point is, Ada doesn't have a good type system. It relies on the programmer doing a ton of proving in some other language like Coq or whatever and then turning off the dynamic checks that Ada does automatically in order to get a verified and fast program. It's a massive gain in productivity to just do it all at once instead of with different languages and tools like this.
>>
How can I make it so the function will start printing out the first set of dashes. Like right now it only prints 3 dashes, i want to start from a defined # of dashes then move from there. Using recursion.

void triangle(int a, int b)
{
//Base Case - Reach beginning value again
//Recursively increase length of dashes until reach max
//When reach max, we decrement until reach beinning value again

if (a == b)
{
}

//Recursive Case
else
{
cout << "-" ;
triangle(a + 1, b); //A++ until get to amount of B then reroll, B stays the Same
}
}

/*Should look Like:
****
*****
******
*******
*******
******
*****
****
*/

int main()
{

int a = 4;
int b = 7;
triangle(a, b);
system("pause");
}
>>
File: image.jpg (38KB, 434x541px) Image search: [Google]
image.jpg
38KB, 434x541px
I'm back and requesting help with another codewars challenge...

Given: an array containing hashes of names

Return: a string formatted as a list of names separated by commas except for the last two names, which should be separated by an ampersand.

Example:
list([ {name: 'Bart'}, {name: 'Lisa'}, {name: 'Maggie'} ])
// returns 'Bart, Lisa & Maggie'

list([ {name: 'Bart'}, {name: 'Lisa'} ])
// returns 'Bart & Lisa'

list([ {name: 'Bart'} ])
// returns 'Bart'

list([])
// returns ''


The following solution works except that it produces the error.
function list(names){
let str = "";
for(var i=0;i<names.length;i++) {
if( names[i].name != names[names.length-1].name &&
names[i].name != names[names.length-2].name) {
str += `${names[i].name}, `;
} else if (names[i].name === names[names.length-2].name) {
str += `${names[i].name}`;
} else {
str += ` & ${names[i].name}`;
}
}
return str;
}
>>
>>59336690
Ada's type system is great. Just because the compiler doesn't require you to put if statements around every single arithmetic operation doesn't mean it's poor.
>>
>>59336725
>The following solution works except that it produces the error.
produces the error in the image.jpg
>>
>>59336729
What can the type system do more so than, say C++?

Yeah you can specify invariants for your types but these don't participate in type checking at all, they're just done periodically at run time. You can prove these invariants externally and switch off the dynamic checks, but you don't use Ada to do so.
>>
>>59336751
Ada actually facilitates such a concept in real, valid Ada standard syntax.

Typing allows the compiler to do some optimization, by removing checks that are not necessary.

More obvious information to the user what the pre contact and post contact and global side effects of a function are.

Guaranteed failure for logical errors pertaining to type limits.
>>
>>59336725
I'd do it like this.
function list(nameArray){
if (!nameArray || nameArray.length == 0) {
return '';
}

if (nameArray.length == 1) {
return nameArray[0].name;
}

let lastName = nameArray[nameArray.length - 1].name;
let otherNames = [];
nameArray.forEach((name) => {
otherNames.push(name.name);
});

return [otherNames.join(', '), lastName].join(' & ');
}


I'm not up to date with ES6/7 so I'm sure there's some fancy new methods to shorten this.
>>
>>59336305
I ordered a M590E GSM kit.
I haven't looked into it yet but you could start with that.
>>
>>59336838
I forgot to remove the lastName from the array, so use
let lastName = nameArray.pop().name;

instead
>>
>>59336815
>Typing allows the compiler to do some optimization, by removing checks that are not necessary.
If the compiler can determine that they are redundant. This involves the compiler being more complex, taking longer, and still not being able to do as much as a human can. That's where the external proofs come in.

>More obvious information to the user what the pre contact and post contact and global side effects of a function are.
And these are checked dynamically for the most part. This is worse than checking statically for all the same reasons you want a static type system over a dynamic type system. A stronger type system essentially lets you turn more dynamic checks into static verification.

>Guaranteed failure for logical errors pertaining to type limits.
Again, done dynamically except for constants.
>>
>>59335307
anyone?
>>
>http://www.uxmatters.com/mt/archives/2007/01/applying-color-theory-to-digital-displays.php
dark themes btfo
>>
>>59335933
s = '({0}{1}{2}) {3}{4}{5}-{6}{7}{8}{9}'
x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
print s.format(*x)
>>
>>59335307
>>59336956
the session ids are stored in a cookie.
>>
>>59336923
The redundancies are noticed by the type system, so no extreme complexity.

Most of them are yes, but the user will be less likely to send bad values to a function specifically requesting certain numbers. Since Ada is strongly typed, and with the added information, giving a function bad data is rare.

Miles better than C++, which is what you asked for. And can be statically checked trivially, as far as the user is concerned.
>>
>>59336815
>>59336923
All this being said, Ada does do a good job of helping programmers to verify their programs externally, much more than most languages. You simply can't beat having a high degree of static verification as part of the language itself.
>>
>>59337018
I don't know if I'd call the type system itself much better than C++. The facilities for dynamic checking are way better (C++ has assertions and that's it) but, again, not the type system itself.
>>
Anyone else here working on classified military projects with Haskell and Assembly?
>>
>>59336723
help pls. :>
>>
>>59336979
If you're not doing anything fancy with the order of the inputs, you don't have to numerically label each of your brackets.
>>
>>59337043
The dynamic checking is so good BECAUSE of the type system. Ada also lends itself to static verification, from the very start, 30 years ago.
>>
>>59336370
Thanks for the response!

Unfortunately, the code you provided gives the same error... I'm thinking of just asking StackOverflow if I can't get this by a couple of hours from now

Bit of a follow up question, why can't I declare the << operator as a member function? Like, why would I need to add the "friend" keyword
>>
>>59336729
>Ada's type system is great
Does it have dependent types?
>>
>>59337186
Yes
>>
>>59337248
Demonstrate it.
>>
>>59337255
http://www.ada-auth.org/standards/12rat/html/Rat12-2-5.html
>>
>>59337186
>dependent types
I have still never seen a valid use for these in my entire life.
>>
>>59337277
Epic.
>>59337281
They are a minimal requirement for a type system to be considered non-garbage.
>>
>>59337333
>They are a minimal requirement for a type system to be considered non-garbage.
Why?
>>
any good sources on learning design patterns/algorithm shit?

... preferably with js ;o
>>
>>59337366
Because anything which doesn't have them is pretty much untyped as far as I'm concerned.
>>
File: 219-hindi%20through%20english.jpg (51KB, 410x640px) Image search: [Google]
219-hindi%20through%20english.jpg
51KB, 410x640px
>>59337384
>>
>>59337384
no, java is trash, redditor. leave. just fucking leave and spare yourself from further embarrassment.
>>
>>59337387
But why?

You haven't explained at all, you just keep saying that they are required, without justifying it.
>>
>>59337384
>js


go to fucking wdg
>>
I'm writing a python program which teleoperates a small radiotelescope and uses the measurements to draw a map of the milky way.

The choice of python is mainly because of libraries and compatibility with telescope hardware. I am getting a bit annoyed at python's crippled lambdas and map/filter/fold functions though.
>>
>>59336723
>>59337103

public class Triangle {

public static void main(String[] args) {
triangle(1, 7);
}

static void triangle(int a, int b) {
// Base Case - Reach beginning value again
// Recursively increase length of dashes until reach max
// When reach max, we decrement until reach beinning value again

if (a == 0) {
return;
}

if (a == b) {
a = -a + 2;
}

// Recursive Case
for (int i = 0; i < Math.abs(a); i++) {
System.out.print("-");
}
System.out.println();

triangle(a + 1, b); // A++ until get to amount of B then reroll, B
// stays the Same
}

}
>>
>>59337406
>But why?
They allow less programs which have errors (obvious or otherwise) to pass type-checking.

I didn't claim they were "required". I'm just that anything that doesn't have them might as well be completely typeless (aka garbage) as far as I'm concerned.
So they are a barrier of sorts, a pleb filter.
>>
>>59337401
you embarrassed yourself pretty heavily with that post desu
>>
_<_ : Nat -> Nat -> Prop
_ < zero = False
zero < succ _ = True
succ m < succ n = m < n

Array : Set -> Nat -> Set
Array A zero = Unit
Array A (succ n) = A * Array A n

Index : Nat -> Set
Index n = (i : Nat) * (i < n)

subscript : {n : Nat} -> Array A n -> Index n -> A
subscript {zero} () (_, p) = absurd p // this case can never come up because (_ < 0) is false (uninhabited)
subscript {succ n} (a, _) (zero, _) = a
subscript {succ n} (_, as) (succ i, p) = subscript as (i, p)
>>
>>59337507
Fuck off, Rajesh. You sperged out for literal months wrapping your poo-in-loo "buu huuu animoooooooooo" statements in code blocks for every thread.
>>
>>59337524
What language? Agda? Should I learn it or Idris?
>>
>>59337566
Pseudo-Agda. Learn Idris.
>>
>>59336984
If someone duplicated your cookie with the session id in could they not trick the site into thinking they have logged in/ it's their session?
>>
>>59337543
I don't know what you are talking about, just hope you know that js and java are different things anon.
>>
>>59337634
Not at all, just repeat after me:
>would you like fries with that?
>>
>>59337491
>They allow less programs which have errors (obvious or otherwise) to pass type-checking.
Why would this be a good thing?
>>
>>59337733
Why wouldn't it? Did you misread it or something?
>>
>>59337733
The only thing you need to believe to accept that it's a good thing is the following: errors are undesirable.
>>
>>59337401
>js
>java
Are you retarded?
>>
>>59337798
>Yes I shit on streets so what?
weird
>>
File: 1341619539905.jpg (107KB, 613x533px) Image search: [Google]
1341619539905.jpg
107KB, 613x533px
>>59337733
>Programs doing what you specifically don't want is ok
>>
>>59337733
Embarrassing!
>>
>>59332981
https://fgiesen.wordpress.com/2011/07/09/a-trip-through-the-graphics-pipeline-2011-index/
Reading this.
It's really good.

What's with the ':)' though? They're everywhere and it looks so condescending all the time.
>>
>>59337479
This is close, but it seems can never get to base case of a==0. End up getting a stack overflow. Thank you though, getting much closer.
>>
>>59337683

>not at all
Anon...

JS is weakly, dynamically typed, and is run directly from source, which is JIT compiled into native code. The same program that does lexing and parsing of grammar is the same program that does native code generation.

Java is strongly, statically typed, and is compiled into bytecode, which is then JIT compiled by a VM into native code.

In JS, a prototype model is used instead of a class model for object creation, as opposed to Java, which is strictly class-based. Moreover, JS allows for free functions, whereas in Java, if one wants a free function, one must instead create it as a static method.

JS was designed to run inside of a web browser, and to cause as few errors as possible. As a result, it lets a lot of "funny business", like adding strings and integers together, or subtracting a string from an array, and returning NaN, a float. Java, by comparison, was designed to run inside a virtual machine, and will throw exceptions like it is nobody's business. It will also hit you with compiler errors if you try to do certain things that shouldn't make sense to begin with.

These are VERY different languages, and you are a moron for believing that there is any similarity aside from the first four letters of their names. And incidentally, JavaScript isn't even the proper name for the language anyways, it's ECMAScript.
>>
>>59337384
http://realtimecollisiondetection.net/blog/?p=81
>Design patterns are spoonfeed material for brainless programmers incapable of independent thought, who will be resolved to producing code as mediocre as the design patterns they use to create it.
-Christer Ericson, Currently VP of Technology at Activision (the company that owns Blizzard) who has a very technical background and has written Real-Time Collision Detection.

The only reason to learn design patterns is if you want to work with losers.
>... preferably with js ;o
So yeah. Go learn design patterns I guess.
>>
File: 1458993598219.png (103KB, 400x400px) Image search: [Google]
1458993598219.png
103KB, 400x400px
>>59337954
baited for this exact response
>>
I am fucking around with making a browser game and trying to identify what is giving me framerate issues. I created a test page that gives me pretty much the same results. IE and Chrome give me close to 60 FPS while bouncing around a bit. But FF 52 gives me a framerate at a steady rate of <10 FPS. I know FF is shit, and Javascript is shit, but this is unacceptable. I am not using requestAnimationFrame because I figured it shouldn't be required for my shitty game.

// Framerate testing
var canvas;
var context;

function drawFramerate(framerate) {
context.fillStyle = "rgb(255, 0, 0)";
var text = framerate.toFixed(2);
context.fillText(text, (canvas.width / 2) - (context.measureText(text).width / 2), (canvas.height / 2) - 10);
}

function loop() {
var t = window.performance.now();
update();
draw();
var execution_time = window.performance.now() - t;
var framerate = 1 / execution_time;
drawFramerate(framerate);
setTimeout(loop, 0);
}

function update() {
}

function draw() {
context.clearRect(0, 0, canvas.width, canvas.height);
}

window.addEventListener('load', function() {
canvas = document.getElementById('gcanvas');
context = canvas.getContext('2d');
loop();
});
>>
>>59338097
What language?
>>
>>59338042
you sound like you're a great guy to hand out with
>>
>>59338112
Javascript
>>
>>59338097
Logical thinking has a direct correlation with IQ.
>>
>>59338128
My entire post is pretty much just the quote.
>>
>>59338171
I disagree vehemently.
>>
>>59337613
yes.
>>
File: 1484669762267.jpg (50KB, 512x509px) Image search: [Google]
1484669762267.jpg
50KB, 512x509px
I'm working on a front end to ZFEC that is meant to be a kind of back up system. I posted my repo in the last thread for someone but he apparently left before I posted.

If anyone is interested in checking it out I'll repost the github repo for it. shit is gpled obviously
>>
>>59338097
don't use settimeout but requestanimationframe to do your main loop
>>
>>59338241
Same results.
>>
>>59332981
Programming is shit.
>>
>>59338174
Ok.
I don't care for Javascript or people who think it's a good idea to learn javascript. Or people who use design patterns and think they're a good idea. Doesn't particularly make me a bad person to hang out with though.
Implicit in this is that I don't like people who don't think. Since it's not hard to come to these conclusions if you look at the programming industry just a little bit.

Perhaps people who give a shit aren't "fun" for you. But that doesn't say either of us are particularly bad people to hang out with. We're just not interested in the same things.
>>
>>59337169
just tried this:
#include <iostream>

struct Index
{
int xInd, yInd;
Index(int x, int y): xInd(x), yInd(y) { }

bool operator<(const Index& rhs)
{
return (xInd < rhs.xInd);
}

friend auto& operator<<(std::ostream& out, const Index& i)
{
out << "(" << i.xInd << ", " << i.yInd << ")";
return out;
}
};

int main()
{
Index i(5, 5);
std::cout << i << std::endl;
return 0;
}

compiles fine here with gcc 6.3.

operators with two arguments are non-member functions. that's just the way things are. member operators (with a single argument) imply the struct type is on the left hand side of the operator, with the argument on the right.
normally you would define a non-member operator outside the struct, but you can't access private data in a non-member function. that's why you need to declare the function as a "friend" of your class. from there, you can define the function body inside your struct as well, even though it's technically not a member of your struct.
>>
File: triangle.png (38KB, 1152x1018px) Image search: [Google]
triangle.png
38KB, 1152x1018px
>>59337892

works fine for me
>>
File: haskell-book.png (44KB, 672x888px) Image search: [Google]
haskell-book.png
44KB, 672x888px
Is good?
>>
File: 1484966990277.png (239KB, 372x508px) Image search: [Google]
1484966990277.png
239KB, 372x508px
>>59338340
Why do you use a struct in a C++ program?
>>
>>59338368
Why not?
>>
>>59338368
The only difference between struct and class in C++ is the default visibility.
class
{
public:
}
//is like a
struct{
}
>>
File: 1466800367189.gif (94KB, 500x275px) Image search: [Google]
1466800367189.gif
94KB, 500x275px
>>59338384
Because it has objects, and it is an object oriented programming language
>>
>>59338217
interesting. Few more questions, after the session ends is the cookie deleted? is the session id deleted? is it only deleted under certain circumstances? What actually generates the session ID, and how?
>>
>>59338366
I prefer the wikibook.
>>
>>59338392
>>59338384
structs can't polymorphism
>>
>>59338368
because OOP is a mistake
>>
>>59338393
write fizzbuzz in smalltalk then try telling us that c++ is "object oriented language"
>>
>>59338405
Completely wrong
>>
>>59338393
It's a multi-paradigm programming language.
>it has objects
It has classes..
>it's an OOP language
Most would say you "can do" OOP in C++ but it's not really an OOP language.
>>59338405
Polymorphism has to do with virtual functions..
>>
>>59338366
Nope.
>>
>>59338366
No, use the wikibook
>>
>>59338405
I suggest you take a C++ program and change the classes to structs with private: at the top of them. See what breaks.
>>
File: 1472919571125.png (233KB, 520x423px) Image search: [Google]
1472919571125.png
233KB, 520x423px
If classes and structs are exactly the same, why do they both exist?

Why not just pick one (probably structs in this case because C had them too) and remove the other?
>>
File: foxfps.png (43KB, 1288x485px) Image search: [Google]
foxfps.png
43KB, 1288x485px
>>59338097
you aren't measuring fps but how long it takes to execute your functions.
if you look at the browsers frame rate you can see all of them rendering at 60fps doing your loop.

https://codepen.io/anon/pen/NppZWm
>>
>>59338531
Fuck off furfag
>>
>>59338531
Structs have no tools to prevent access to internal data from outside.
>>
What's the best laptop on the market right now for programming?
>>
File: heresy.jpg (94KB, 482x641px) Image search: [Google]
heresy.jpg
94KB, 482x641px
>>59338531
Anon if you start asking such heretical questions you might begin to understand that C++ is not a good language.
I advise you to stop.
>>
>>59338547

>why would you want this
>>
>>59338547
They do.
Write
private:
in your struct.
>>
>>59338549
>>
>>59338547
I don't get this data hiding meme. If everything is properly documented and properly written, why would it matter that every object can access it's children's data?

Don't you trust the people working with your code (often that's just you) enough to not abuse the variables you mark as "DO NOT CHANGE BUT FEEL FREE TO ACCESS"?
>>
>>59338549
any laptop, as long as it has a buckling spring keyboard.
>>
>>59338400
php sets a session cookie, once you close the browser the browser forgets those.
php generates the id.
php has no knowledge when you close your browser, but sessions have a timeout, once it runs out and no request has been made by that id php forgets it.

go look in their source code how they generate it.
https://github.com/php/php-src/blob/d9bfe06194ae8f760cb43a3e7120d0503f327398/ext/session/session.c#L284
>>
>>59338574

:(((((

Might as well just carry my desktop around.

Isn't there anything compact and semi-powerful?
>>
New thread:

>>59338603
>>59338603
>>59338603
>>
>>59338583
That's the OOP meme. You encapsulate things to ensure the users of your objects are accessing your data "correctly".

It's not a good idea. But that was the idea. If you want the favorable argument there's plenty of OOP preachers all over the internet. I'm not gonna repeat it.
>>
>>59338598
Compact and programming doesn't mesh well imo. You need a good keyboard.
>>
>>59338572
Whatever, I don't know C++
>>
>>59338643
Kinda rude to mislead someone about it then but it's only a drop in the bucket of the confusion he has to face with C++.
>>
>>59338660
I tried to answer from my knowledge standpoint.
You were more clever, I'm wrong.
Sorry me please.
>>
>>59338679
No problem. But when I'm uncertain and tell people things I generally make it clear I'm uncertain.
>>
>>59338694
I was certain that that is the main difference of C++ classes from C structs.
>>
>>59338719
Yeah sure, we all make mistakes.
>>
>>59333035
what is the purpose of that comma?
>>
>>59338340
Thanks! I found out that there were actually two issues! One was that I was compiling with C++11 instead of C++14 (how I didn't figure this out sooner speaks to my lack of programming experience), and the other was kind of weird

I had a function that adds Index instances to a set (I had the '<' operator overloaded), but when I ran it, it would give me the "Invalid operands to binary expression" error.

I changed the '<' operator from :
    bool operator<(const Index& rhs)
{
return (xInd < rhs.xInd);
}

to
    friend bool operator<(const Index& lhs, const Index& rhs)
{
return (lhs.xInd < rhs.xInd);
}

And now it works! Would you happen to know why making '<' a non-member operator took away this error (even though in both cases I had const Index instances?)

Thanks for all the help, though!
>>
>>59339811
oh that's odd. I don't immediately see any problems there. the const thing may have something to do with it, even though I don't think that matters when comparing integers.
you could try declaring the operator function const too, eg:
bool operator<(const Index& rhs) const

which should make the implicit "this" pointer a "const Index*" so you would be comparing two const integers. again I don't really see how that matters here.
>>
>>59339811
Less than requires two arguments you big dummy

Friendship doesn't matter
Thread posts: 326
Thread images: 34


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.