[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: 323
Thread images: 25

File: hime on the front page!.jpg (94KB, 500x701px) Image search: [Google]
hime on the front page!.jpg
94KB, 500x701px
old thread: >>55754086

What are you working on, /g/?
>>
File: 1467398868589.jpg (475KB, 852x973px) Image search: [Google]
1467398868589.jpg
475KB, 852x973px
First for Haskell


pls wait until bump limit next time
>>
>>55760118
First for two early post.
I'm learning about this MVVM clusterfuck.
>>
>>55760118
Do it for Him(e)!
>>
First for Lua.
>>
>>55760137
>can't tell if this is elegant or spaghetti

dropEvery :: [a] -> Int -> [a]
dropEvery xs n = if length xs >= n
then (take (n - 1) xs) ++ dropEvery (drop n xs) n
else xs
>>
Am I doing this database thing correctly?
sqlite3 *db;
sqlite3_stmt *stmt;
sqlite3_open("data.db", &db);
sqlite3_prepare_v2(db, "SELECT field FROM sample;", -1, &stmt, NULL);
while (1)
{
sqlite3_step(stmt);
int len = sqlite3_column_bytes(stmt, 0);
if (!len)
break;
char *data = (char *) malloc(sizeof(char) * len + 1);
char *col = (char *) sqlite3_column_text(stmt, 0);
strcpy(data, col);
printf("%s\n", data);
free(data);
}
sqlite3_finalize(stmt);
sqlite3_close(db);
return 0;
>>
File: 1443949854681.png (1MB, 1280x720px) Image search: [Google]
1443949854681.png
1MB, 1280x720px
>>55760182
>>
>>55760170
i got you senpai
dropEvery ∷ [a] → Int → [a]
dropEvery xs n | length xs >= n = take (n - 1) xs ++ dropEvery (drop n xs) n
| otherwise = xs


would look neater with a where clause
>>
>>55760203
thanks
but what about the functions used? i was originally thinking of matrixifying the list and mapping butLast over them and then concat, but that doesn't work if the last list is not full.

is there a idiomatic/insightful answer here?
>>
File: 1464409852833.jpg (353KB, 870x500px) Image search: [Google]
1464409852833.jpg
353KB, 870x500px
>>55760203
>mfw all this gibberish
>>
>>55760118
I want to inseminate hime
>>
>>55760233
here's another, dropEvery looks much nicer in this

splitAround n xs =
let (front,back) = splitAt n xs in
(take (n-1) front, back)

dropEvery ∷ [a] → Int → [a]
dropEvery xs n | length xs >= n = front ++ back `dropEvery` n
| otherwise = xs
where (front,back) = splitAround n xs


you can use backticks to infix a function
>>
>>55760262
whoops
front ++ (back `dropEvery` n)
got the associativity wrong
>>
>>55760193
compiler warning
>>
>>55760292
What shitty compiler are you using?
>>
>>55760233
not sure what you mean by this, & why would that not work for the last one
>>
File: 1442710170306.png (24KB, 850x400px) Image search: [Google]
1442710170306.png
24KB, 850x400px
>>55760182
>>
>>55760118
Why people say that Linux based oses offer great tools/environment for devs?

Can you give me an example?
>>
>>55760262
using
import Data.Bifunctor (first)

splitAround n xs = dropLast `first` splitAt n xs
>>
never programmed before and i want to get good at C, should I go bottom up by starting with assembly and then working on C or top down from Haskell or Python?
>>
>>55760338
Tons of language implementations that do not suck. Tons of high quality software.
Shell, editors, compilers and terminal emulators that do not suck dicks.
>>
>>55760366
You cannot fool me, you have actually programmed before!

Writing FizzBuzz 24/7!
>>
>>55760338
let's see
to install a library, you just type apt-get install libwhatever and link it with -lwhatever in gcc.

To get that shit working on windows, you need to install the latest version of visual studio 2016, download outdated windows binaries for libwhatever, copy the header files into your project directory, add them to your environment PATH, and it probably won't work anyway
>>
>>55760366
If you want to learn C just start with C.
>>
>she
>>
File: 20160722_210153.jpg (1MB, 2560x1920px) Image search: [Google]
20160722_210153.jpg
1MB, 2560x1920px
>>55760380
But they are available on Windows too.
>>
>>55760389
I use VS Enterprise I have it all.
>>
>>55760395
Only some of them as shitty buggy painful to use ports.
>>
>>55760193
>>55760292
>>55760300
I like to do this to maintain compatibility with C++ compilers.
>>
>>55760366
>>55760392
Might be easier to start with something like Python, C may be overwhelming for a beginner.
>>
>>55760430
But that's stupid.
>>
>>55760338
All of them come with compilers and relevant dev tools like GNU Make pre-installed. Library installing is a straight forward thing, just search for it with your package manager. Its just much simpler to jump into than Windows development where there's a million things you need to do to even start.
And things aren't overcomplicated. All you need is a terminal and you're ready to program. Everything from man pages to debuggers to profilers to what ever you need is there.
>>
>>55760441
The best option would be to start with Scheme and SICP if he actually wants to learn.
>>
>>55760302
i mean something that gives insight into the problem, possibly using haskell/ocaml-unique functionality. something like http://evan-tech.livejournal.com/220036.html

it would work if I just did take (n - 1) instead, I think
>>
what's something cool I can make in java as a beginner
>>
>>55760430
>>55760193
>>55760292
>>55760300
Also, an even better solution would be to size of the de referenced pointer instead of its data type.
>>
>>55760464
http://cs61b.ug/sp16/materials/proj/proj2/proj2.html
http://cs61b.ug/sp16/materials/proj/proj3/proj3.html
>>
File: dropEvery.png (19KB, 515x287px) Image search: [Google]
dropEvery.png
19KB, 515x287px
>>55760459
I don't really see there being a particularly special implementation for this specific problem
>>
>>55760182
>>55760465
What if the result has a null terminator in it? Then strcpy will stop prematurely.
>>
>>55760502
and yes it's possible the length check is redundant
>>
>>55760456
I actually want to learn, so whats the complete path I should take? Scheme and SICP -> Python -> C?
>>
>>55760506
better to terminate early than to cause a segfault
>>
>>55760515
Scheme and SICP -> C -> asm/Haskell
>>
>>55760502
fair enough, thanks.
>>
>>55760522
Might as well use strdup then instead of doing the malloc and all that yourself.
>>
>>55760526
Someone else answered the other day and said
"first learn haskell
then learn python
then learn c#
then learn c++
then learn x86 asm
then you might be ready to learn c"
>>
>>55760545
You could always index the items in the list and then check modulo n
>>
>>55760565
He was clearly trolling as C is easier than (and mostly a subset of) C++. It's also much easier than x86 assembly.
Moreover, nobody would suggest Haskell to someone who just started.
>>
>>55760118
>She
>>
>>55760594
Who the hell are you quoting?
>>
>>55760545
>>55760568
here's a very inefficient example


import Data.Bifunctor (first)

indexed ∷ [a] → [(Int,a)]
indexed [] = []
indexed (x:xs) = (0,x) : (first (+1) <$> indexed xs)
-- extremely inefficient

dropEvery' ∷ Int → [(Int,a)] → [(Int,a)]
dropEvery' n = filter (\(i,_) → i `mod` n /= 0)
-- ((/= 0).(`mod` n). first)
dropEvery n = (snd <$>) . (dropEvery' n)
>>
File: Tommy_Lee_.png (102KB, 345x230px) Image search: [Google]
Tommy_Lee_.png
102KB, 345x230px
>>55760583
>C is easier than C++
>>
>>55760643
(snd <$>) . (dropEvery' n) . indexed
>>
When should I use references as arguments for functions in C++?

When should I return them?

Why don't I just always accept/return objects?
>>
>>55760756
I'm so confused ;_;
>>
>>55760756
never

use & whenever you want to pass a local variable as a pointer to another function

returning objects is wasteful, especially once you start dealing with structs that hold non-trivial amounts of data.

and they usually have pointers to pointers inside of them, so good luck returning a struct by value and not by reference.
>>
>>55760756
Whenever you don't want to copy them
>>
>>55760756
>When should I use references as arguments for functions in C++?
When
a) The structure is so big you don't want to copy it for the argument as it would take too long
b) When you want to manipulate the referenced object in the function.

>When should I return them?
Depends. If you want to provide, say, access to a private class member, you can make a function that returns a reference to it. If you want to make it a read-only thing, make the function return a const reference.

>Why don't I just always accept/return objects?
I don't understand.
>>
any way to ssh without opening a port via your router?
>>
>>55760847
ssh localhost
>>
>>55760338
Toolchain integration with the OS.
Everything runs in the terminal emulator, vim/emacs, git, gdb, valgrind, C programmers have access to POSIX and manual pages for everything all without leaving the terminal, and the only build system worth a shit relies on gnu code so that would involve cygwin if you wanted to have that on windows.

For C# and other .NET stack stuff windows is a must, but C and C++ programmers will have better workflow under linux.
Interpreted languages work fine on any system in my experience.

But really if you're writing C or C++ that does not compile under linux then you're doing it wrong.
>>
File: 1469306842052.jpg (289KB, 734x1200px) Image search: [Google]
1469306842052.jpg
289KB, 734x1200px
>>55760583
C is simpler, but for this very reason it is harder to use.
A bit of a dark art as they say.
First rule of C is that if you don't already know the first rule of C then you're retarded and should kill yourself.
>>
>>55760931
Easier to learn, simpler to use.
>>
If I want to create a cross-platform program (Android, iOS, Win, Linux), would I have to write the backend for it in C++? Or are there other options? (besides rewriting from the ground up for each platform)
>>
Please stop posting cute anime girls. They make me want to cry. That feel when no gf.
>>
>>55760942
>girl
>>
>>55760942
>girl
Anon I have some news for you..
>>
>>55760952
>>55760957
Fucking japs literally drawing girls and calling them boys. Fucking retarded Jap homos.
>>
>>55760964
>homos
The author of himegoto is actually a girl.
Checkmate
>>
>>55760976
Rekt
w/ No Respekt
>>
>>55760939
I find Java to be the best for cross-platform. However, this is only if you NEED to do it. I'd suggest using each platform's native language. C# for Windows and Swift for macOS. Linux is whatever you want.
>>
File: 1469501448545.jpg (36KB, 361x441px) Image search: [Google]
1469501448545.jpg
36KB, 361x441px
>>55760942
>>55760964
Welcome to /g/

Enjoy your stay
>>
>>55760964
>Fucking japs literally drawing girls and calling them boys
Yes, and?
>>
>>55760526
If he wants to learn C why would you direct him to asm/Haskell after C? Useless if you're not going to be using it
>>
>>55760170
dropEvery :: Int -> [a] -> [a]
dropEvery n = go (n-1)
where
go :: Int -> [a] -> [a]
go _ [] = []
go 0 (x:xs) = go (n-1) xs
go k (x:xs) = x : go (k-1) xs


This one is more efficient (try to avoid ++)
>>
How do I get a comfy C job?
Everyone wants a degree and 5 years experience for an entry level job.
>>
>>55761016
so he can get good
>>
>>55761042
That's pretty.
>>
>>55761042
What's the point of haskell if you're just going to write obfuscated imperative code?
>>
>>55761097
that's not obfuscated and definitely not imperative either
>>
>>55761048
Github.com

Do some projects and believe me start-ups will spam the shit out of you. Understand what you're getting in to though. However, if you want to be with a big company, you need schooling unless you have good connections and whatnot. Be that from LinkedIn or whatever, just network in general.
>>
>>55761114
ok, here's how I would do it in python.

def drop_every(xs, n):
result = []
for idx, x in enumerate(xs):
if idx % (n+1) != 0:
result.append(x)
return result


That code seems in the exact same spirit. You're iterating through the list. I realize by this definition the implementation of "map" or "filter" is iterative too, but in general why not use higher order functions?
>>
>>55761137
idx + 1 % n, I mean
>>
>>55761137
You can write any list operation with foldr, but adding "k" to the accumulator becomes a bit clumsy.

My version is lazy and (I believe) is a "sufficiently good consumer" so that it can be fused with other list operations. That alone is a very nice improvement over the imperative version.
>>
>>55761175
What is a sufficiently good consumer?
>>
>>55761175
Your function is strict in the pattern matching except for the _. Also in a situation like this a case statement is better. Pattern matching in a where clause is ugly.
>>
what fucking idiot invented fat32
>>
>>55761226
ctrl+f "good consumer" here: https://downloads.haskell.org/~ghc/7.2.2/docs/html/users_guide/rewrite-rules.html

>>55761260
It's strict in the mathematical sense, yes. In a practical sense, this just evaluates the list to WHNF for n > 0, not NF.
>>
>>55760526
Can anyone else vouch for this learning path?
>>
>>55761597
Some fat guy in his 30's.
>>
>>55761884
got a silent giggle out of me
>>
I think Swift is my new favorite language.
I feel kind of dirty.
>>
File: code.png (348KB, 1349x612px) Image search: [Google]
code.png
348KB, 1349x612px
Be honest with me guys, do I code like Pajeet?
>>
>>55761849

Scheme / Sicp -> C was a pretty standard path for a long time in colleges. Sicp got phased out for python and C was phased out for C++ / Java / C#.
>>
>>55761930
eh, looks fine
start commenting and you are on your way to being a bona fide Anglo-saxon programmer
>>
>>55761948
Would I be walking on a path to extinction if I go for the Sicp -> C route as opposed to Python -> Java? If employers think it's an outdated skill set that might be a little off-putting...
>>
>>55761930
>class
Full pajeet.
>>
>>55761973

Sicp -> C then pickup C++ / C# / Java

By then it'll just be picking up new syntax. Your base skill set will be relatively strong.

Also get used to the common frameworks in the field you wish to pursue. Pretty much every job expects sql knowledge and the ability to use the microsoft monopoly products.
>>
>>55761930
>sans serif
REEEEEEEEEEEEEEEE

>>55761849
depends what you want to learn/what your goal is. it can either be perfect or terrible depending
>>
>>55760526
should have
asm -> then learn to do that shit in C so you never have to use it again
>>
>>55762044
its Verdana you fucking pleb
>>
>>55762070
might be easier to learn C first then asm then go back to C
>>
>>55760389
>he doesn't know about NuGet

install-package My.PackageName
>>
fapping to traps and working on GNU Turd
>>
>it's another thread where the newbies get meme'd to start on Scheme, C, ASM, and Lisp

I guess it's our version of a fingerbox.
>>
>>55762485

Dpt just likes to prescribe a curriculum that is like college programs around the 80s / 90s.
>>
How to start learning erlang? It looks really hard...
>>
So I'm starting fulltime soon. What are some resources I should read before going in?

I might refresh myself on networks.
>>
>>55761930
Yes, remember to close your reader.
Instead of:
String input;
...
while(true)


You should have:
for (String input;;)

This is a personal thing but I like to use "final" where possible. I don't see any "final"s in your code.

I don't see any comments or documentation of functionality.
>>
File: 6wPXUYc.png (1MB, 687x1000px) Image search: [Google]
6wPXUYc.png
1MB, 687x1000px
>>55762485
>>55762709

The top five languages on this list are the only languages that will ever matter. You could extrapolate trends and take gambles on rising languages but learning anything else that is a waste of time and resources.

http://www.tiobe.com/tiobe_index
>>
>>55761930
>>55762737
This is also what I tell 90% of people that post their code to /g/: for the love of god, use an autoformatter.
>>
>>55762744
No, you're a fucking retard.

Javascript is one of the most in-demand languages across all industries, and it's only going to become more prominent.

There aren't that many C jobs on the market. I'm not saying not to learn C, but the majority of programmers never will, and never need to learn C.
>>
>>55762744
>http://www.tiobe.com/tiobe_index

When you realize 2 of those languages are in the top 10 and 3 of them are in the top 30.

A new language is also exposure to different ways of thinking about and solving problems.
>>
>>55762744
>learning languages is difficult or important
lol
>>
>>55761930
> private fields and then method to access them instead of just properties

> creating custom Add class instead of just using constructor to create Bird class and then regular ass generic container Add

if else if else if else if sequence should re-written as switch, OR you can write separate method wuith agument reader.nextLine() corresponding to each of the commands in your console app

i give you three pajeets out of ten pajeets
>>
What do C++ people think about std::function?
I have a pretty simple framework that has a button class, when it gets pressed it should call some sort of callback. First thing that comes to mind is just using a function pointer, but std::function feels more flexible, yet more "messy".

Is std::function something to generally avoid? Lambdas are fun but feel obscure in an OOP framework. My inner C is urging me to just use a "void (*button_pressed)()"
>>
>>55760182
>not _alloca
>>
File: cute_deer.jpg (140KB, 960x960px) Image search: [Google]
cute_deer.jpg
140KB, 960x960px
Is Kotlin a good language? Is it the future of Java or just a meme like Rust?
>>
>>55762850

Depends on what google does with android. If they go the Kotlin route it will get a large market for android apps. If they do end up supporting swift it probably will not pickup very fast.
>>
File: kemeditor.png (88KB, 860x698px) Image search: [Google]
kemeditor.png
88KB, 860x698px
>>55762485
lel
i studied Prolog and Modula while in elementary school

in recent times K was the last programming languages that really blew my mind

All languages that are actually in industrial use feel so pedestrian by comparison
>>
>>55762850
It's a meme.
>>
>>55762829
>alloca
Non-standard garbage.
Even then, C already has a way to achieve the same effect: VLAs.
>>
>>55762897
>VLAs
definetely not all compilers support this
>>
>>55762909
In C99, it's a requirement. C11 made them optional, but most compilers still support them.
Also, how is non-standard shit better than optional standard shit?
>>
Thanks for all the feedback guys
>>55762737
>>55761953
I haven't made any comments because it's an assignment for a online course and I didnt want to waste too much time
>>55762756
What do you mean by autoformatter?
Im pretty sure I used the autoformathotkey in that pic
>>55762802
> private fields and then method to access them instead of just properties
I was thought that youre supposed to do this that way
> creating custom Add class instead of just using constructor to create Bird class and then regular ass generic container Add
I wanted to include the check for duplicate
> if else if else if else if sequence should re-written as switch
course uses older java version that doesnt have switch(String)
>>
>>55762921
because some compilers shrug off standards
>>
>>55762932
>java
lel
i thought it was c# all along
>>
>>55762884
>If they do end up supporting swift
Have there been any talks or even hints about that?
>>
>>55762941
If a compiler doesn't follow the standard, you literally cannot call it a C compiler.
All extensions must not affect the behaviour of conforming programs.
>>
>>55762825
I think it's much easier to read than the more convoluted FPs.

>>55762932
Nvm, you did autoformat it looks like.
>>
>>55762829
>>55762909
>_alloca
I am aware of no proper compiler that supports this trash.
>>
>>55762941
No proper compiler does this.
>>
File: carmack.jpg (91KB, 800x821px) Image search: [Google]
carmack.jpg
91KB, 800x821px
>when Carmack was 14, he broke into a school to help a group of kids steal Apple II computers. To gain entry to the building, Carmack concocted a sticky substance of thermite mixed with Vaseline that melted through the windows. However, an overweight accomplice struggled to get through the hole, and opened the window, setting off a silent alarm and alerting police. John was arrested

How can one man be so based?
>>
>>55762961

http://thenextweb.com/dd/2016/04/07/google-facebook-uber-swift/

Basically google representatives went to a meeting discussing the language. It shows a possible interest. Nothing truly conclusive.

It'd be a bitch of a project for android to transition from java to swift. So there is a good chance it won't happen.
>>
>>55762932
>>55761930
Just thought of something else.

You see how you validate your input in BirdDatabase::add? Well if someone else uses your code they might not validate their input.

So this means that you should have the input validation for Bird::Bird be done inside the class Bird, that way you reduce the amount of "you're using it wrong" bugs.

How do you do this? Two big approaches:
1) Have Bird::Bird throw an exception on invalid input. NB: We have to throw an exception because constructors can't return null.
2) Make Bird::Bird private and have a public static factory method, say Bird::createBird that validates the input then either returns the object, throws an exception, or returns null. NB: because the factory method isn't a constructor it's allowed to return null.
>>
>>55763062
https://en.wikipedia.org/wiki/Builder_pattern
That's another pattern worth looking into.
>>
>>55762850
it's much more of a meme than rust actually
>>
File: vomit.jpg (90KB, 650x650px) Image search: [Google]
vomit.jpg
90KB, 650x650px
>>55763114
>"""design patterns"""
>>
>>55763127
How big is the largest codebase you've worked on? And what's the largest dev team you've been on?
>>
>>55763134
30 million lines of code, 4,000 developers.

All classless, without design patterns, and everyone only used Linux™
>>
have written this for a webpage so that something only happens half the time
 
var d = new Date();
if (d.getTime() % 2 === 0) {/*do something*/}
else {/*do something else*/}

is it retarded?
>>
>>55760118
>you will never be forced to study in a girl's only programming high school
>>
>>55763158
To develop the ultimate fizzbuzz?
>>
File: 1452463042847.png (128KB, 336x377px) Image search: [Google]
1452463042847.png
128KB, 336x377px
>>55763190
The artist of that girl claims that it's a guy, you know.
Although I understand your confusion, because he literally drew a girl.
>>
>>55763177
Yes
>>
>>55763212
I fear that you might not have understood what I posted.
>>
>>55763177
>is it retarded?
Yes, kill yourself.

Unless, of course you don't actually care if it happens half of the time.
>>
>>55763158
"Design patters" don't only apply to OOP, although it is a relatively modern term. There are, for example, acknowledged C design patterns.

You're telling me that in 30 million LOC there were never recurring trends that caused developers to say things like "we should do X in Y way"? And that aside from (hopefully) a style guide, the only guiding principle was "do things however you want"?
>>
>>55763231
>>55763215
VERY rude posts
>>
File: _41176509_sarcasm_416.gif (22KB, 416x300px) Image search: [Google]
_41176509_sarcasm_416.gif
22KB, 416x300px
>>55763235
>>
>>55762451
NuGet repos are very very lacking.
>>
>>55763235
Don't confuse "design patterns" with """"""design patterns"""""".
They are different things.
One is something you might typically do, the other is over-engineered OOP garbage to try overcome the flaws in Java and OOP itself.
>>
/dpt/, help me out.

Say I have the input "Bob Dole".

I want to use "Bob" as a seed to generate a consistent number from 1-791, and "Dole" to generate a consistent seed from 1-1999.

The intention is to put real names through a name generator, and rather than come up with completely random names, "Bob Dole" will come up as "Jane Smith" each time it is fed into the generator.

I'm not sure how to use text to seed a consistent output.
>>
So I have a big ass vector that's size is changed constantly. I have "subvectors" of this vector that are basically structs that keep track of the element index and count in the big ass vector.
Now if a "subvector" A is removed from big ass vector, every "subvector" after A needs its' element index subtracted by A's count.

Do you spot anything bad about this code instantly? First time having to use templates ever. pseudocode, the reference/pointer stuff about subs is probably wrong but understandable.

template <class T>
class container {
public:
struct sub { int elem_index, sub_index, elem_count };
std::vector<T> elems;
std::vector<sub> subs;
sub new_sub(int count) {
sub s { elems.size(), subs.size(), count };
elems.resize(elems.size() + count);
subs.push_back(&s);
return s;
}
void delete_sub(sub s) {
subs.erase(subs.begin() + s->sub_index);
elems.erase(elems.begin() + s->elem_index, elems.begin() + s->elem_index + s->elem_count);
for(int i = s.sub_index; i < subs.size(); ++i) {
subs[i].elem_index -= s.elem_count;
subs[i].sub_index -= 1;
}
}
};


Basically I don't know if this code is shit or not.
>>
>>55763523
Just hash the string "Bob" in some way, seed your random number generator with it and then generate your random number like you would normally.
In terms of actually hashing the string itself, there are all sorts of ways you can do it. There is actually all sorts of research into algorithms for hashing strings (for use in hashtables etc.), so you can probably just search online for high-quality hashing algorithms.
For you case though, it could probably be something as simple as multiplying all of the characters together (as integers) together.
>>
File: Ja6Y8lk.png (19KB, 641x323px) Image search: [Google]
Ja6Y8lk.png
19KB, 641x323px
>>55763612
I think I'm just going to convert characters to integer representations, add them, and then use that as the seed.

In the case that it overflows over the number of possible names I have, I'll just have it wrap back to the beginning. I don't really care about two names having duplicates.

In this case, "Bob Dole" seeds out an integer value of 311, which I feed to a Random object, and I'll use the first and second part of the output of that to grab a first and last name.

I just did two Random objects to prove to myself that it would generate the same first int from the same seed.
>>
I'm diving back into C++ after ragequitting it (entirely because debugging C++ was horrible bullshit) years ago.

What's the best linting tool if I want to ensure I don't have any uninitialized pointers? Null pointers are fine, I just don't want to have to deal with the shit where a pointer with garbage data in it leads to my code treating other garbage data as an object.
>>
>>55763579
Looks like solid C++. If it works then what's the problem?

>>55763754
Constructors.
>>
>>55763764
>Constructors.
ayyyy

The entire point of what I'm saying is that, back in the day, I'd initialize a bunch of shit in the constructor but somehow miss or forget a variable (because I'm a human being and not an automated system, so I can miss shit) and that variable would be a pointer and I'd suffer.
>>
>>55763754
Actually, while I'm at this, what are some of the best / most important features added to C++ and the standard library in C++11 and C++14?

Try to list a top ten if you can do that off the top of your head.
>>
>>55763781
You can initialize variables inside the class definition as well.
class A {
public:
B* my_b = new B(3);
int a = 5;
B other_b(8);
};


Hard to forget it like that.

>>55763819
C++11 has all kinds of cool shit. You find them out as you go, I can't remember any specific features from the top of my head.
>>
>>55763819
Smart pointers
Move semantics
Lambda functions
constexpr
Ranged for loops
override keyword
Variadic templates

etc.
>>
File: XTBmvZc.png (29KB, 1216x326px) Image search: [Google]
XTBmvZc.png
29KB, 1216x326px
>>55763523
>>55763677
Alright, here's my fucked up method so far.

Seems to actually work.

Will optimize after I load it with about 50,000 names in a minute.
>>
>>55763862
>Woll Smoth
Haven't seen that one in a long while
>>
>>55763840
>You can initialize variables inside the class definition as well.
Speaking of new things in C++ 11, **damn**. That's huge.

>>55763858
Cool. How do move semantics work, exactly? Similar to Rust ownership?

Thanks for the feedback.
>>
>>55763259
>backpedaling
>damage control
>>
I'm reading this C++ book from about 10 years ago, and it's telling me to use the Hungarian Notation, meaning i should put the first letter of the datatype (except int) as first letter of the variable name.
For example:
float f_Number = 1.01;
int n_Number = 1;
bool b_Value = true;

Do people actually do this?
>>
>>55763997
I don't
>>
Can't think of the name. Pls help /g/

It's the algorithm strategy where you save results in a dictionary data type and before computing them you check the dictionary to see if they've been computed before you recompute them. I think it's a strategy within dynamic programming. HALP
>>
>>55760182
>no error checking
>sizeof(char)
>casting void*
>useless malloc/free
nope
>>
Getting a big fucking dose of "make my app" and I fucking hate it
>>
>>55763997
yes
>>
>>55764022
>>sizeof(char)
>bad
Casting a void pointer explicitly is generally a good idea. Stop falling for those faggot anime pictures.
>>
>>55764036
>I'm literally retarded
>>
>>55764036
>bad
Yes, it is bad indeed.

>Casting a void pointer explicitly is generally a good idea
Only retards consider it a good idea.
>>
>>55764019
generally known as caching, particularly known as memoization
>>
>>55763983
I think he's bitching about things like AbstractProxyFacadeFactoryFactoryFactories which are a meme and don't actually exist.
>>
File: 3pqyIYB.png (42KB, 1086x589px) Image search: [Google]
3pqyIYB.png
42KB, 1086x589px
>>55763862
Cleaned up and removed a bit of retardation.

Abstracted to method, ready to input straight from database data.

>Sixty Niggers becomes Molly Dejesus
>>
>>55764059
>bitching about things that don't exist
Sounds like he's retarded.
>>
>>55764043
>>55764054
Googled it, turns out you're right. I assumed it was good practice because C++ spits out warnings if you don't cast a malloc. Then again in C++ new[] is the better way.
>>
>>55764059
catch (WeirdExceptionFactoryBean ex)
{
WriteLine("Something happened. " + ex);
}
>>
>>55764080
>Then again in C++ new[] is the better way.
No, in C++ you should use std::vector or other things from newer standards instead.
>>
>>55764080
maybe you should stop assuming things you have no clue about
>>
when using c strings is it better to use char* or char[]? or does it mean in what "context" you're using it? can you also mix both versions or is that ugly?
>>
>>55764087
>WriteLine("Something happened: something happened")
ftfy
>>
>>55763030
>being a niger
>based
>>
>>55764108
char[] is not valid C
>>
>>55764056
MEMOIZATION TY SENPAI
>>
>>55764131
I know but I mean char name[length], you know what I mean
>>
>>55764128
>>55763030
The thermite + vaseline to melt school windows is fucking hilarious and genius.
>>
>>55764108
They are not equivalent (except in function arguments), so it doesn't really make sense to ask that question.
char *str1 = "asdf"; // Not modifiable
char str2[] = "asdf"; // Modifiable

So it depends on what you need it for.
>>
>>55764131
It is
>>
>>55764189
they are different things; neither of them is a string by default
>>
I need a database with info about potential customers and many info about them for a small company, is MS Access good for it
>>
F# Ocaml or Haskell?

The difficult question.
>>
>>55762850
will always be a meme unless Oracle supports it for their JVM
>>
>>55764295
The answer is Erlang.

>>55762850
>or just a meme like Rust

Why is the consensus now that Rust is a meme? Go is the bigger meme, considering as the only reason it's popular is that San Francisco has a hype fetish.
>>
I wish I could have the choice to manage my own memory and have pointers/references in java

a man can only dream
>>
>>55764373
>Erlang
It is useless in 90% of the cases.
>>
>>55764373
>The answer is Erlang.
>Go is the bigger meme
Are you literally retarded?
>>
>>55764405
Just like any other FP language then, so what's the difference.
>>
>>55764250
>MS Access
Baby's first DBMS. Use MariaDB, PostgreSQL, CouchDB or RethinkDB.
>>
>>55764220
is there a way to read in words using char* or do you have to use char yada[length]?
>>
>>55764463
>babby
>mariadb
m8...
>>
>>55764472
nevermind I'm retarded
>>
>>55764425
Explain why Rust is a huge meme and Go is a sane practical choice, please.

Go's dependency management pretty much just grabs the latest revision from the master branch of a git repository for all of your dependencies, so every time somebody makes a breaking change your shit is fucked. The community's solution is apparently vendoring, which causes legal issues (if you redistribute vendored code) and eats an unreasonable amount of space by code standards.

Also it's supposed to be a systems programming language / C competitor but it has mandatory garbage collection, with a garbage collector that is slow as shit compared to Java.

Also, the lack of type genericism and the lack of operator overloading make certain types of problems impossible to express without a metric shitload of boilerplate and, with the no generics thing specifically, not-statically-typed byte buffer casting shit.

I can understand not liking Rust, because I don't like Rust (fugging borrow checker), but at least it exists for a coherent reason and has a community for reasons other than "Google made it."


The Erlang thing was shitposting, though. :^)
>>
suggest a 3rd language for me
already know a bit of C and Python
>>
File: icon-ruby.png (89KB, 959x833px) Image search: [Google]
icon-ruby.png
89KB, 959x833px
I'm trying to write an asynchronous framework for Ruby, using Fibers to avoid callback hell.

Here's what I have so far:

https://github.com/AnthonySuper/KitchenSync

How bad is it?
>>
>>55760809
>If you want to provide, say, access to a private class member, you can make a function that returns a reference to it.


this sounds like a design flaw of C++

non-members shouldn't be able to point at and modify private data

> If you want to make it a read-only thing, make the function return a const reference.

yeah, you better do
>>
>>55762773
t. pajeet or nu-male from a san fran startup
>>
>>55764563
Javascript
>>
>>55764667
I'm glad that there's at least one person out there that agrees with me that SF fags singlehandely ruin the programming world.
>>
I just finished a Huffman Coder and I'm wondering if this decode method can be done any better. The input String is a bit string, a HuffCodePair has String ID and String code. ID is the char it represents and code is the Huffman bit representation for that char. The extract method returns the char given a bitstring.
    private static String decode(String input, ArrayList<HuffCodePair> codeList) {
String result = "";
char[] inputArr = input.toCharArray();


for (int b = 0; b < input.length();) {
boolean found = false;
String cur = "" + inputArr[b];
while (!found) {
if (linearSearch(cur, codeList)) {
result += extract(cur,codeList);
found = true;
b++;
} else
cur += inputArr[++b];
}
}
return result;
}
>>
I wanna write a program and open source it, but I want to provide Windows builds for it too. I want them to be really simple, just download and run. Can I do that with autotools? Can I get it to produce a Windows package that includes all the necessary libs?
>>
>>55764563
Haskell.
>>
>>55764709
Can't you just use Visual Studio for the Windows Builds?
>>
>>55764667
>nu-male

I hate San Francisco as much as the next man, and Javascript too, but please don't try to meme about how certain kinds of programming are "manly" or "unmanly." Reason: That's fucking retarded.
>>
>>55764709
apples and oranges
>>
>>55764463
Its for a small company who are not tech literate I need just to make so they can do advanced searches by keywords and have their info displayed to them easily
>>
>>55764728
I would really prefer to stay in Linux, and also not have to maintain two sets of build files.
>>
>>55764737
Okay: JavaScript isn't for effeminate people, it's for thick people, who went to code bootcamps and similar things.
>>
>>55764563
why not work on a project with the skills you already have instead of learning another language?
>>
>>55762800
Winner
Why does everyone argue?
It takes two weeks tops to learn a new language if you need to for any reason.
>>
>>55764537
native csp
>>
>>55764770

because I can do both
>>
>>55764801
Only if you're considering languages with only superficial differences, like Java, C#, Python, etc.
>>
>>55764856
Unless you're already an expert in the top 5 languages, or a company requires a specific language, why would you not work on those top 5 languages?
>>
>>55764876
Because the amount of code repetition and boilerplate they require bores me to tears?

When I program as a hobby, I want it to be fun.
>>
>>55764481
what's wrong with it ?

>Its lead developer is Michael "Monty" Widenius, one of the founders of MySQL AB and the founder of Monty Program AB. On 16 January 2008, MySQL AB announced that it had agreed to be acquired by Sun Microsystems for approximately $1 billion. The acquisition completed on 26 February 2008. MariaDB is named after Monty's younger daughter Maria, similar to how MySQL is named after his other daughter My.[9]
>>
anyone here used ROS?
I'm currently learning it for a course and it's most convoluted and complex shit I've ever had to deal with
>>
>>55764917
Fair enough!
>>
>>55764537
>vendoring causes legal issues
How so?

>mandatory garbage collection, with a garbage collector that is slow as shit compared to Java
Firstly, unlike Java Go allows you to choose between allocating on the stack or the garbage-collected heap. This helps reduce GC load drastically. Secondly, as of 1.6 GC pauses are never longer than 10 ms. Please point me to a resource that claims the JVM has shorter pauses than that. To add, a new transactional GC is being worked on, that should enable goroutine-isolated pauses ala Erlang. Those are practically realtime.

>generics
There currently isn't an implementation invented that can facilitate both fast compile times (seconds on your cheap laptop for most projects and 10 minutes for stuff that used to compile for 2 hours on a cluster with C++) and not boxing everything like Java.

>reason
Easy to maintain, read and learn, fast to compile server language with good performance in this use case.
>>
In my makefile I have

OBJ       = $(C_SOURCES:.c=.o)


Anyone know how I can add .s to this too? .s to .o
>>
>>55765018
If some of my code pauses for 10ms then there's going to be a problem.
>>
>>55765068
OBJ = $(C_SOURCES:.c=.o) $(S_SOURCES:.S=.o)
>>
>>55765088
Thanks
>>
>>55765018
I thought the way vendoring works pretty much requires that you include the full source of somebody else's library in your repo. Isn't that how it works?

>Go's garbage collector isn't shitty any more
Oh, that's actually really good news!

>fast compile times
I have no idea why this is such a priority. I understand that you don't want the crazy 2-hours-on-a-distributed-build-server shit that happens with big C++ projects, but surely a little compile time is a worthy sacrifice for a major language feature that's the only way to make data structures without C-style void* stuff.
>>
>>55765081
Most of us don't write missile guidance software, anon.
>>
>>55764373
>>55764537
>Why is the consensus now that Rust is a meme?
Rust has no IDE support, no compatibility with the libraries that matter (those written in C++), and no jobs. It's dead in the water. Meanwhile, if you know what you're doing, your C++ code will be just as solid, and faster to boot, than anything you could write in Rust.

The whole thing is just an embarrassing display of NIH, like the Mir debacle. There was no reason to make this language.
>>
>>55765081
the stop-the-world gc was replaced with a concurrent one in go 1.5
>>
>>55765138
>no compatibility with the libraries that matter (those written in C++)
чтo

Rust has full FFI support for the C ABI. https://doc.rust-lang.org/book/ffi.html
>>
>>55765115
>requires that you include the full source of somebody else's library in your repo
it doesn't; it just requires that source to be available at build time in the "vendor" subdirectory; it doesn't have to be in your repo: it can be a git submodule (ie. only a reference to another repo), it can be retrieved as a pre-build step from whatever source you want, etc.
and you don't even have to use the vendoring "feature" (I don't even know why they bothered to special case it); just use whatever source control tool you want to manage your workspace (again, as git submodules/subtrees, svn externals, etc)
>>
>>55764667
I'm literally a burly dude in the South who's got years of experience in the industry.

>I don't agree.
translates to
>pajeet
>reddit
>nu-male
>cuck
>other memeword
>>
>>55765183
That's nice. So does Python. Now try using it with a C++ header-only library and tell me what happens.
>>
>>55765183
>written in C++
>C ABI
>>
>>55765232
>header-only library
aka copy+paste snippet
>>
>>55765214
Post muscles
>>
>>55762773
>Javascript is one of the most in-demand languages across all industries, and it's only going to become more prominent.
>>55765214


Honest question, not here to meme - if I want to learn JavaScript, is it worth starting a desktop application or server-side thing in Node.js? Or, should I wait until I have some webdev-related project to work on?

I don't have any ideas for web apps, but I want to get hired someday.
>>
>>55765288
You could certainly do a UWP application in HTML5+JS.

I would think that would be easier than fucking with a webpage.
>>
>>55762485
This will leave someone with a better foundation then just going python to Java, may be outdated but it's effective period.
>>
>>55765138
>no IDE support
doesn't matter
>no compatibility with the libraries that matter (those written in C++)
nothing else is compatible with C++ libraries because C++ has no stable ABI; also there aren't many C++ libraries that actually matter
rust looks dead because it doesn't bring significant improvements to justify using it instead of C++ (at least for now)
>embarrassing display of NIH
>no reason to make this language
true
>>
>>55765288
>worth starting a desktop application or server-side thing in Node.js
no; it's a shit language and a shit framework; use it in the browser, it's the only place you have to
>>
>>55765351
>but it's effective
That depend on what you consider effective.

ASM and C are not effective in the vast majority of job roles.

You do not need to know either to be an efficient Java/C#/C++ developer.

Should you understand how memory works to be a great developer? Probably.

Do you need to spend months learning C or ASM to learn how memory works? Nope.

What you're basically proposing is old school dev vs a variant of agile. Take a year and see results all at once, or take a few months and immediately get some value.
>>
>>55762485
>newbies get meme'd to start on
>Scheme, C, and Lisp
That'd be okay. C is questionable but you can write in a newbie subset of C, sorta.
>ASM
WHAT
wHY
>>
>>55765497
If you're going to learn C as a 'foundation', might as well go down to ASM or machine code for a particular architecture first, right?
>>
>>55765436
If a beginner emerged themselves in the classic approach with C and the like they will end up with a better foundation to tackle problems in "irrelevant" languages like Java or C++. If you've been coddled along with languages like Python from the beginning you can bet the guy that took the 80s/90s approach is going to have a better grasp at just what the hell he's doing. Besides who cares if you don'the end up using C, you can always pick up a language relatively quickly once you've got that solid foundation.
>>
>>55765579
I don't want to hear shit about what you consider effective language teaching methodology if you can't determine the difference between emerged and immersed.
>>
>>55765579
Fun facts: Knowing both C and something like Python or Lua is a sublime pleasure, since you can write Python and then say "oh this section of code needs to be faster" and then re-write it as a C module for Python.
>>
>>55765579
>you can bet the guy that took the 80s/90s approach is going to have a better grasp at just what the hell he's doing
That's absolutely wrong.

There's a reason that major companies are specifically hiring graduates with no formal experience.

The guy from the 80's/90's is going to be a great consultant or manager, but as an employee, he brings his own habits and preferences in and causes issues.

>Besides who cares if you don'the end up using C, you can always pick up a language relatively quickly once you've got that solid foundation.
You're probably NOT going to end up using C, and you could start with another language that you can more quickly be employable in. It doesn't matter if you learn C or Java, either way, you have a basic understanding of how programming works.

The meme of
>if you don't start with C it's super hard to learn C!
is simply wrong. There's a reason that the best universities are teaching high-level languages first.
>>
I think I've figured out San Francisco:

They're all on either weed or cocaine, or both.
>>
>>55760118
So how can I make my python script print a message with a launch option or whatever i.e
python script.py -h

output:
hello
>>
>>55765754
https://docs.python.org/3.3/library/argparse.html

Is that what you want, Anon?
>>
>>55765754
Use the argparse module.
>>
>>55760502
got sauce on that theme?
>>
>>55765754
https://docs.python.org/2/library/getopt.html
>>
>>55765646
You don't think a guyear from a classical background is able to just dumb down to the level of his Pythoname colleagues? It'seems easier to dumb down from C to Java or Python then it is to smarten up from Python to C. By the way your post is kind of contradictory, you talk about undesirable habits from C programmers but at the same time say getting bad habits before learning C is a meme (it's not more difficult).
>>
>>55765232
>>55765239
>what is "extern C"?
Wrapping C++ libraries in C is trivially easy.
>>
>>55764616
>this sounds like a design flaw of C++
I wouldn't argue it's good design, but I suppose the good thing is that if a member variable isn't available via any other method but by a function that references it, it sends a message to the user that they'll probably want to think about it a bit before manipulating the variable. References are what allow for things like singletons (which I'm not arguing are a good thing either, but I guess they have their uses.)

Anyway, the original idea and purpose of references is very simple: a safer pointer (that is, it can't as easily point to NULL, for example.) Additionally, "private" and "public" are nothing but syntactical sugar in C++ - there's always a way to access a private variable - they're supposed to simply act as a guide to the programmer rather than real barriers.
>>
>>55765870
quick, wrap boost! fucking retard
>>
>>55761097
you could write it imperatively if you like, using State or ST & it would likely perform better
>>
>>55765949
I don't think it would perform any better, not on this simple program. I don't see how state would even help here, what state do you need to keep track of?
>>
>>55765826
>mother of autocorrect
>>
>>55760964
What's wrong? You don't like male girls?

Truly terrible taste.
>>
>>55766031
you could use
forM_ and modify (x:)
so that it would accumulate a list in an imperative fashion
>>
>>55766080
Ok, that works, but unwrapping the state computation underneath it will end up being the same computation as the stateless version above, while introducing more overhead with function calls (which may or may not be optimized away)
>>
>>55766141
not necessarily

imperative code is easier to optimise
>>
>>55765646
I think Scheme is good to learn simply because SICP is such a great resource
>>
What's the best IDE for C++ on Linux? CodeBlocks?

Preferably something with integrated debugging.
>>
>>55766153
There are great resources for languages that are more commonly used for real-world applications.
>>
> C++

what does
 return {something}; 
do in C++ ?
>>
>>55766315
Depends on the return type but basically initializes the object of return type via initializer list.
>>
https://github.com/rusthon/Rusthon
Could somebody please explain what the fuck I'm looking at? The repo does a terrible job of it.
>>
>>55766324
makes sense, thanks
>>
>>55766347
Rusthon
>>
>>55766347
Looks like markdown preprocessor that compiles/runs snippets contained within the text document, are you blind?
>>
>>55766369
har har

What in the actual shit does this lunacy do? And how is it backended? I see a bunch of Python interop with C and Go, and Markdown is involved as some kind of container (what the fuck?) but how is Rust involved?
>>
>>55766389
What makes you think that it has anything to do with Rust other than having a backend support for it?
>>
>>55766268
RDPing to a Windows computer running VS
>>
>>55766271
very hard to find a better resource than SICP for beginner programmers
>>
>>55766493
Unfortunately, this.

Or use a VM.
>>
Does anyone know a good introduction to sql databases in android studio?

my head really hurts trying to get into this
>>
>>55766574
http://sqlbolt.com/ is very good
>>
File: powershell.png (342KB, 640x480px) Image search: [Google]
powershell.png
342KB, 640x480px
anyone knows bit of powershell?

Get-AppxPackage


command will print out all the "apps" installed on windows 10

but it prints all the fucking details, name, publisher, date, fullname, framework, bundle, path,... all the works...

I want just to print the names of installed packages
>>
>>55766689
You probably have to pipe it into into
Select Name
or something like that.
>>
>>55766689
Get-WmiObject -Class Win32_Product | Select-Object -Property Name
>>
>>55766737
 | Select-Object -Property Name


works with appx as well
I just want those apps, not all installed software
>>
File: 150602_2870595_Portia_Doubleday.jpg (451KB, 2560x1440px) Image search: [Google]
150602_2870595_Portia_Doubleday.jpg
451KB, 2560x1440px
>>55766737
oh, and thnx btw
>>
>>55766657
>http://sqlbolt.com
thanks mi lad, but I understand sql in general, i'm abut the implementation in java
>>
>>55760937
No you fucking mongol, a stick is simpler than a hammer, that doesn't mean it's a simpler effort to build something with a fucking stick than with a hammer.

Concrete example since you're clearly a stubborn little shit:
error handling in babby C++
try
{
boost::fuck_you();
}
catch whatever
{
std::babbycout << ":) Ooops, something happened!";
}


Error handling in C
#include <stdio.h>
#include <stdarg.h>

#ifdef __GNUC__
__attribute__ ((format(__printf__, 1, 2)))
#endif
_Noreturn void die(const char *format, ...)
{
va_list vargs;
va_start(vargs, format);
vfprintf(stderr, format, vargs);
va_end(vargs);
exit(1);
}

#define DIE(format, ...) die("%s:%d in %s()\n" format, __FILE__, __LINE__, __func__, __VA_ARGS__)
>>
Finishing up Programming: Principles and Practice Using C++ in a few days, on last chapter

What should I read after?
>>
>>55766536
The majority of programmers have never read SICP and are doing just fine, take your garbage language and go away.
>>
>>55766798
Effective C++ books by Scott Meyers
>>
>>55766778
>>55766764
anytime
>>
>>55766798
how would Bjarne know "real world" programming ?
>>
>>55766781
most of them are identical
you open up a database connection object, create precompiled bytecode "prepared statements", and then run them with sql_step() or whatever your library provides.
Grab the column data with sql_column(stmt, column_no) or similar
>>
>>55764250
MS Access ofers you two building blocks: data storage and forms.
A nice replacement would be some web app with SQLite database.
Why SQLite? Because your average Access app won't support concurrent users, while SQLite allows your app to be used by a (small) number of users simultaneously, and at the same time is very light on resoures and requires very little maintenance.
>>
>>55766831
How outdated are they?
>>
>>55766389
It's some weird Python-like language that compiles to a bunch of other languages. For some reason you write the source code embedded in markdown files. I think it's someone's attempt at literate programming.
>>
>>55766975
"Effective C++" is pretty outdated, "More Effective C++" is still relevant, and "Effective Modern C++" is very much up to date.
>>
NEW THREAD!!

>>55767074
>>
>>55766797
>Error handling in C
This is not the case, kill yourself.
>>
.
>>
can someone explain to me what a driver is
>>
>>55767370
the person who steers the car
>>
>>55763840
>You can initialize variables inside the class definition as well.
not statics
>>
guys what do you think of my first shortest path finding algorithm ? i used BFS

#include<iostream>
#include<list>
#include<queue>
#include<vector>
#include <stack>
#include <stdlib.h>
using namespace std;

list<int> adj[1000];
queue<int> q;
stack<int> path;
bool test,vis[1000]={0};
int v,e,n,i,j,a,b,s,x=0,y=0,k=0,parent[1000]={0};

int par(int x)
{
if (x>0)
{

if (x==a )
path.push(a);
else
{
path.push(x);
return par(parent[x]);
}
}
else
{
//stack<int> temp;
// swap(path,temp);
cout<<"sorry there's no way to get from "<<a<<" to "<<b;
}
}


void bfs(int n)
{
vis[n]=1;
while(! adj[n].empty() ){
if(! vis[adj[n].front()])
{q.push(adj[n].front());
parent[adj[n].front()]=n;
vis[adj[n].front()]=1;
if(adj[n].front()==b)
test=1;
}
adj[n].pop_front();
}

if(! q.empty() && test==0)
{
// cout<<q.front()<<" ";
q.pop();
bfs(q.front());
}

}


int main()
{
cout<<"Vertices|edges"<<endl;
cin>>v>>e;
cout<<"From|To"<<endl;

for(i=1;i<=e;i++)
{
cin>>x>>y;
adj[x].push_back(y);
adj[y].push_back(x);

}
cout<<"path a -> b"<<endl;
cin>>a>>b;

q.push(a);
bfs(a);

cout<<endl<<"Shortest path from "<<a<<" To "<<b<<" : ";
par(b);
while( path.size()>1)
{
cout<<path.top()<<"->";
path.pop();
}
cout<<path.top();
}

/*test case 7 6 1 2 1 3 2 4 2 5 3 6 3 7 1 6*/


is there anyway to optimize it ?
also, i want to do a similar algorithm for a weighted graph now can BFS do it?
>>
>>55767543
int v,e,n,i,j,a,b,s,x=0,y=0,k=0,parent[1000]={0};

what
>>
>>55767543
> is there anyway to optimize it ?

yeah, get rid of recursive calls

and learn to use objects since you're writing a c++ algorithm
>>
>>55767614
i can get rid of most of them but they aren't causing any harm :c

>>55767631
i thought recursion is the best way to do it? how do i do it then ? and how do i store and then later find the parent of each node then?
>>
>>55767631
>removing tail calls
>optimisation
lol
>>
>>55767803
I think I experimented with it enough in g++ an llvm, it's slow as shit at least in non-trivial cases
>>
>>55765872
Pardon the noob question here, but can you elaborate on what you mean by guide to the programmer? Would you be talking about things like mutators/accessors, and safe pointers like the 'this' keyword by chance?
Thread posts: 323
Thread images: 25


[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.