• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

Double post. I owe it to you all to explain what my frustration in C++ was. It started with this line:

Code:
auto startTime = std::chrono::high_resolution_clock::now();
I wanted to put this in its own function. But I didn't want to keep auto. I think it was giving me my hundreds of template instantiation errors but you can never be sure. (Will concepts fix this? Who knows.) That and I needed to do things with the return type.

Tried jumping to ::now()'s definition. "No definition found". Oh no... So then I tried jumping to high_resolution_clock's. "No definition found". Oh shit. Ctrl-f'd in chrono's header file (which is not suffixed by an h. Nice!). Found this gem.
Code:
// To support the (forward) evolution of the library's defined
    // clocks, wrap inside inline namespace so that the current
    // defintions of system_clock, steady_clock, and
    // high_resolution_clock types are uniquely mangled. This way, new
    // code can use the latests clocks, while the library can contain
    // compatibility definitions for previous versions.  At some
    // point, when these clocks settle down, the inlined namespaces
    // can be removed.  XXX GLIBCXX_ABI Deprecated
Thanks bjarne :^) This is also why this part of the library has its own cast for time-deltas "duration_cast".

Don't worry, though. If you have issues with C++, you can always use C and C avoids these issues. C avoids these issues by being useless for complex tasks. Hurray!
 
Double post. I owe it to you all to explain what my frustration in C++ was. It started with this line:

Code:
auto startTime = std::chrono::high_resolution_clock::now();
I wanted to put this in its own function. But I didn't want to keep auto. I think it was giving me my hundreds of template instantiation errors but you can never be sure. (Will concepts fix this? Who knows.) That and I needed to do things with the return type.

Honestly this is exactly what auto is for. I'd try to figure out the template errors. Note that you can use decltype to get the exact type of the expression without knowing what it is

Code:
using NowType = decltype(std::chrono::system_clock::now())

And you can use that expression in a return type as well

Code:
auto foo() -> decltype(std::chrono::system_clock::now())
{
}

And if you can use c++14 you can just drop the decltype portion of that

Last edited by Spoiled Milk; Today at 07:13 PM. Reason: waiting for cppking's "you're an idiot" response
Nah, shit is complicated. Luckily it gets progressively more simple with each iteration of the standard
 
Honestly this is exactly what auto is for. I'd try to figure out the template errors. Note that you can use decltype to get the exact type of the expression without knowing what it is

Code:
using NowType = decltype(std::chrono::system_clock::now())

And you can use that expression in a return type as well

Code:
auto foo() -> decltype(std::chrono::system_clock::now())
{
}

And if you can use c++14 you can just drop the decltype portion of that


Nah, shit is complicated. Luckily it gets progressively more simple with each iteration of the standard
Debugging template errors is daunting, but it's probably good practice. Thanks for the decltype tip. I should also just embrace auto.
 

Koren

Member
I hate C. And I hate C because I hate macros.
I regularly hate them too (use D ;) ) but in that case, it's rather a matter of complex include chains than macros, no?

Note that you can use decltype to get the exact type of the expression without knowing what it is
Thanks god, although it sometimes makes things even messier... You replace the need to know the correct type with the idea to create you own name for the type, different in each part of the file...
 
I've cut down my hours at work to put time into building a portfolio. The problem is, I'm a bit lost on what to work towards (school didn't really help with that). I would like to work with SQL and either C# or Java. I guess I should probably have a website as well.

Anyone have any suggestions on what would be a good project to work towards to generally impress prospective employers?

Thanks!
 

Makai

Member
I've cut down my hours at work to put time into building a portfolio. The problem is, I'm a bit lost on what to work towards (school didn't really help with that). I would like to work with SQL and either C# or Java. I guess I should probably have a website as well.

Anyone have any suggestions on what would be a good project to work towards to generally impress prospective employers?

Thanks!
Make something you actually want to make independent of your resume.
 
I've cut down my hours at work to put time into building a portfolio. The problem is, I'm a bit lost on what to work towards (school didn't really help with that). I would like to work with SQL and either C# or Java. I guess I should probably have a website as well.

Anyone have any suggestions on what would be a good project to work towards to generally impress prospective employers?

Thanks!

Do you like sports? Quick recommendation is a fantasy football application written with Spring framework. Very easy to CRUD your database with a basic RowMapper.
 
Thinking of getting a new workstation for personal use. My laptop runs on 4GB of RAM and it's simply too slow. I don't need a beefy workstation. I do some Java but nothing too intense. I will sometimes deploy Tomcat but that's about it. Not too interested in emulation or Android development. Anyone have some recommendations?

I prefer Mac OSX but I am inclined to try something new. Not a big Windows guy but I would entertain Linux. Anyone have experience with these Surface Laptops?
 

SOLDIER

Member
Think I'm finally going to give the A+ certification a shot.

Anyone able to recommend the best (as in easy to understand) guides (also free, if applicable)? I would prefer something written so I could read it during work, but I won't oppose video guides either.
 
I'm building a forum in Django, mostly as a learning exercise.

I'm wondering what people's thoughts are on URLs, slugs and uniqueness.

At the moment I've decided that this is a simple and basic forum at least for now.

A forum consists of sections, sections contain threads and threads contain posts.

A thread has a section and a poster.

A post has a thread and poster.

So that's the basic design out of the way for the moment.

Right now after thinking for a little while I decided to make my URLs structured like this:

root/section/<section-slug>


root/thread/<thread-slug>

For the slug I have a slugified version of the title of either the section or the thread depending on which you are viewing.

Is this the right approach do you think? I have seen some forums that combine the title with the id from the database for example:

root/thread/thread-title-20547/

Is it better to keep the id out of the URL as it makes it more readable?

Finally a question on uniqueness. For the moment I've decided that sections should have unique titles as they should all be separate and small in number and generally predefined.

My question is more related to threads...should a thread title be unique? (at least when taken together with the section that contains the thread)

Sorry for the wall of text just rattling my brain on these design decisions to try to find some kind of best practice. Thanks in advance for any advice!
 

Lister

Banned
Finally a question on uniqueness. For the moment I've decided that sections should have unique titles as they should all be separate and small in number and generally predefined.

My question is more related to threads...should a thread title be unique? (at least when taken together with the section that contains the thread)

Personally, I wouldn't require the thread title to be unique, but I would check to make sure it is. If it isn't, I'd append a number or Id, what have you, to the slug.
 

Pixeluh

Member
Well, I decided to buy The Unreal Engine Developer Course - Learn C++, due to recommendations on this forum. It looks interesting and hopefully it'll aid my studies in C++, especially since i'll be learning it in school!

I looked at my purchase history and it seems I also bought The Web Developer Bootcamp by Colt Steele over a year ago. I briefly went through the course when I was interested in web development, but did not think it was beneficial. At the time, instead of actually learning, I was just copying everything the man was typing. I learned absolutely nothing from it and didn't retain a single ounce of information.

Perhaps I'll go through it one more time in the future to refresh my terrible web development knowledge, lol.
 
Well, I decided to buy The Unreal Engine Developer Course - Learn C++, due to recommendations on this forum. It looks interesting and hopefully it'll aid my studies in C++, especially since i'll be learning it in school!

I looked at my purchase history and it seems I also bought The Web Developer Bootcamp by Colt Steele over a year ago. I briefly went through the course when I was interested in web development, but did not think it was beneficial. At the time, instead of actually learning, I was just copying everything the man was typing. I learned absolutely nothing from it and didn't retain a single ounce of information.

Perhaps I'll go through it one more time in the future to refresh my terrible web development knowledge, lol.


Seems really cool. That's a pretty loaded course, too. Enjoy it.
 

tokkun

Member
Is this the right approach do you think? I have seen some forums that combine the title with the id from the database for example:

root/thread/thread-title-20547/

Is it better to keep the id out of the URL as it makes it more readable?

You are probably better off having the id in the URL but omitting the thread title. Then it is possible for a thread to be renamed without the URL changing. As a general rule, you should avoid using anything as an identifier that someone might conceivably want to change in the future. That's how you end up in situations like PSN, where it is not possible to change gamer tags.

Putting user-supplied strings in your URL also sounds like a hassle, and potentially a security risk. You would need to be careful about sanitizing them to ensure they are valid URLs and don't do anything weird to the user's browser.
 
today I learned long is not always equivalent to usize_t. Thanks c++. lol

Ftfy. :)

Even if msvc didn't do this, the standard says it's implementation defined, and even if every known compiler does something a certain way, making assumptions like that still technically undefined behavior

Another good one is that the C standard only guarantees that RAND_MAX be >= 32768. Well, in MSVC that's exactly what it is, essentially making it useless (some might argue that's a good thing, since it's already useless, and this just makes it harmful to force you to use something else
 

Koren

Member
Not sure I follow your comment. I think we agree c++ needs modules, but what does that have to do with RAND_MAX or size_t/long? Or repositories (source control?)
Well, in this case, not much... AFAIK, the <random> in C++x11 is good.

But with all the workforce behind C++, I find unfortunate that managing dependancies is still that hard, especially when a usual install will have a lot of things missing. For people that come from Python, Javascript and the like, CGet, NuGet and other managers seems crude compared to pip, conda, bower and the like.

I'm not that fond of pip and the like, but after giving up on using a library because I couldn't compile it, I'd say C++ isn't the more user-friendly language there is...
 
Well, in this case, not much... AFAIK, the <random> in C++x11 is good.

But with all the workforce behind C++, I find unfortunate that managing dependancies is still that hard, especially when a usual install will have a lot of things missing. For people that come from Python, Javascript and the like, CGet, NuGet and other managers seems crude compared to pip, conda, bower and the like.

I'm not that fond of pip and the like, but after giving up on using a library because I couldn't compile it, I'd say C++ isn't the more user-friendly language there is...

Ahh, right. But then again, user friendliness was never one of c++'s stated goals, certainly not at the expense of remaining close to the machine.

Having a package management system while supporting native code and multiple platforms is not an easy proposition
 
You can just look at the reference? http://en.cppreference.com/w/cpp/chrono/high_resolution_clock Sorry dude, but I'm not buying your argument. Any sufficiently large and complicated code base will be difficult to dig through - it's a result of trying to make the code easier to maintain among a team. The way you counter this problem is by making better documentation. This is why you had trouble going to the source first. The source is built so that a web of highly trained kernel developers can maintain and introduce new kernel dev hopefuls to it. As an end user, the materials written for you are the man page or cppreference.
Nice try, but there is no kernel being written in C++ because of ABI concerns. Just look at that name mangling comment I posted. Any kernel module written in c++ would definitely broke if it had to rely on that.

...but I still should have read the docs.
This is another potential use case of auto if you were assigning a long with something of type size_t. See Effective Modern C++ by Scott Meyers Item 5:

Ex.



It may help prevent future headaches.
Actually I wasn't using c++. I was doing some ffi, exposing bits of a c function, and was wondering whether or not I could just cast as a word and be done with it.
 
Actually I wasn't using c++. I was doing some ffi, exposing bits of a c function, and was wondering whether or not I could just cast as a word and be done with it.

Ah that sounds interesting. Mind if I ask about your use case?

I don't have much direct experience with that outside of being a user of a heavily managed scripting language that can make C++ calls. I certainly don't need to worry about variables sizes.
 

Koren

Member
Ahh, right. But then again, user friendliness was never one of c++'s stated goals, certainly not at the expense of remaining close to the machine.
You don't have to make compromise on anything language-related to build a tool to make dependancies more streamlined (edit: well, maybe choices about h-files/encapsulation related, but we agree that modules are better?). I think ignoring the user-experience is a mistake. C++ won't go anywhere because there's a lot of things that rely on this, and a huge effort behind, but I can see more and more newcomers hating it.

I even have a love/hate relationship with it myself.

I'd be curious to know the language that programmers favor, depending on their age...


Having a package management system while supporting native code and multiple platforms is not an easy proposition
Those tools wouldn't even need to be cross-platform. For example, pip isn't really CP (using it on Windows is a nightmare, thanks god conda is better, even if its objectives are a bit different)

Even for a single platform, and a single compiler, it's a mess. I don't think VC has a nice, working solution. Linux has a slightly better one with aptitude and *-dev packages, but it's not perfect, and a LOT of libraries aren't supported.

Indeed... Though you won't replace C++ with rust, there's far too many problems with that (designing a scalable graph in Rust is a nightmare, for example)

But I can see programmers embracing Rust more easily because of this kind of stuff.
 
You don't have to make compromise on anything language-related to build a tool to make dependancies more streamlined (edit: well, maybe choices about h-files/encapsulation related, but we agree that modules are better?). I think ignoring the user-experience is a mistake. C++ won't go anywhere because there's a lot of things that rely on this, and a huge effort behind, but I can see more and more newcomers hating it.
I wouldn't say ignore, just at the expense of giving full control. If the c++11, 14, 17, and 20 standards are any indication they obviously care and are taking many steps to improve it, but you can't do it at the expense of the very principles that made c++ as successful as it is.


Those tools wouldn't even need to be cross-platform. For example, pip isn't really CP (using it on Windows is a nightmare, thanks god conda is better, even if its objectives are a bit different)

Even for a single platform, and a single compiler, it's a mess. I don't think VC has a nice, working solution. Linux has a slightly better one with aptitude and *-dev packages, but it's not perfect, and a LOT of libraries aren't supported.
Yea not the tools, the packages themselves. Just think Python extension modules. It's a huge pain in the ass
 

Koren

Member
at the expense of the very principles that made c++ as successful as it is.
Historical randomness? :D

Yes, that's a troll ;) but I truly believe that C++ workforce behind a different language would have brought something better. Starting with D. The main thing that made C++ (and Java) successful is inertia after a good show at the beginning, and the fact that languages on the foreground receive more help than others.

I don't believe there's a single *principle* that make C++ stand over other languages.

And that's coming from someone that still choose C++ for almost all large-scale projects.
 
Historical randomness? :D

Yes, that's a troll ;) but I truly believe that C++ workforce behind a different language would have brought something better. Starting with D. The main thing that made C++ (and Java) successful is inertia after a good show at the beginning, and the fact that languages on the foreground receive more help than others.

I don't believe there's a single *principle* that make C++ stand over other languages.

And that's coming from someone that still choose C++ for almost all large-scale projects.

It almost certainly would make a better language. But people and companies naturally put more weight behind short and medium term goals over long term ones. "Let's make a brand new language and deprecate hundreds of millions of lines of code" is not really an appealing proposition. So instead they get different people to make these new languages, with fewer resources, and eventually if one grows to the point that it serves many of the same needs, old code in the old language can start to go away.

The flaw is in thinking there's some magic bullet, or that "all you need" is a language which is better on paper. It needs to be better enough that you're willing to transition millions, or even billions of lines of code to it, and that only happens over a very long time period
 

Koren

Member
Personally, I wish they had the balls to break backward compatibility on a couple of things, so that they can improve the syntax.

In many cases, C++x11/14 syntax is better, they should simply make old syntax incorrect, or at the very least deprecated (I'd actually make this incorrect, with a possible flag to enable the old syntax for compatibility purpose, till you can update the sources).

I'm pretty sure that in most cases, you could even translate automatically old syntax into new one. The only 'bad' thing is that a lot of printed ressources/online tutorials would become deprecated, though.


They did it with Python 3k, a lot of people weren't not fond of seeing their code not working anymore, but at least the bases are safer.
 
Hey ProgrammingGaf - I've been thinking lately on what I should do as a Computer Engineer and I've been wondering how is the iOS developer segment. It's something I can actually like instead of some boring jobs like my friends have. Anyone can share some knowledge on this?
 
Personally, I wish they had the balls to break backward compatibility on a couple of things, so that they can improve the syntax.

In many cases, C++x11/14 syntax is better, they should simply make old syntax incorrect, or at the very least deprecated (I'd actually make this incorrect, with a possible flag to enable the old syntax for compatibility purpose, till you can update the sources).

I'm pretty sure that in most cases, you could even translate automatically old syntax into new one. The only 'bad' thing is that a lot of printed ressources/online tutorials would become deprecated, though.


They did it with Python 3k, a lot of people weren't not fond of seeing their code not working anymore, but at least the bases are safer.

Specific examples you had in mind? I'm still not sold on the Python 3 decision, to this day most code is still being done in Python 2 and it's been how many years?
 

Koren

Member
Specific examples you had in mind?
Better encoding support, better exceptions, saner typing, far more logical syntax, far saner choices (how "1<sin" has any sense?), a lot of functions returning iterators instead of lists, normalization about magic methods...

I'm still not sold on the Python 3 decision, to this day most code is still being done in Python 2 and it's been how many years?
Inertia, again... There's not a single reason to go for Python over Python 3k, except for module unavailability, and there's less and less problems with those (http://py3readiness.org/).

I'm not even sure about the "most code is still being done in Python 2" part.

Python (2) is dead even if it still doesn't know it ;) Python is reaching end of support (2020, it should even have happen earlier), IPython dropped Python support and is Py3k only now since april (and that's huge), research and education are probably more Py3k than Python, several large companies are strongly behind Py3k (such as RedHat or Facebook). Several companies will hang to Python till it's done for, as they keep using Windows XP.
 
Inertia, again... There's not a single reason to go for Python over Python 3k, except for module unavailability, and there's less and less problems with those (http://py3readiness.org/).

Well sure, but if anything that's just a case study in how much inertia actually matters in practice.

There are still reasons to use Python 2 over 3. Most importantly, the OS distribution you're using ships with Python 2 (I'm looking at you, OSX), and Python makes side by side installs a pain the ass (I'm looking at you PYTHONPATH, you son of a bitch)
 

Munti

Member
Hi everyone, I have a question.

I'm in a situation where I can attend a course that will be partially paid. However, the list of these courses is quite limited.

Now there's one of the bigger courses where I would get the certificate "Oracle Certified Associate, Java SE 8 Programmer". Does anyone know if this certificate is worth it?
 

Koren

Member
Well sure, but if anything that's just a case study in how much inertia actually matters in practice.
I'd argue that it's a proof that it doesn't matter that much. Of course, there's a decent amount of inertia (COBOL is still popular! And I know a lot of researchers that use F77) but Python 3.0 is just 8 years old, and 3.0 wasn't that stable. In less than a decade, they'll have a switch, and they could have had it faster (they shouldn't have put the end of life of Python that far in 2020).

Should you break a couple of legacy syntax with, let's say, C++X17, granted, there'll people that will stick with older versions, but honestly, it's already the case. I'm not sure that X11 is even that widespread. After all, the C > C++ jump has broken things, that hasn't stopped C++ popularity.


There are still reasons to use Python 2 over 3.
You'll find reasons for most things, but really valid ones, that's sometimes harder ;) 5 years ago, definitively. Now, not that many.

I grant you, rewriting code is expensive (though not that much in this case), but more often than not, if 2to3 doesn't work, it's because the code is poorly written / ambiguous to begin with.

Most importantly, the OS distribution you're using ships with Python 2
Which one? Most Linux distribution are jumping on Py3k... like RedHat, Fedora or Ubuntu (though in Ubuntu case, they kept both).

I'll grant you Debian, but it's a special case, it shouldn't be a distribution for end users, and if you use it, you know that you're far behind the times (I mean, the last THREE times I installed a stable, I had to switch to testing because my processor or something else was too "recent" to be supported... I had freezes because of Sandy bridge integrated GPU, for example). And while Python (2) is the default, none are technically in the base distribution (priorities are standard and optional, resp., if I'm not mistaken). I hope Buster will make the switch.


Python doesn't come with Windows, and I'm pretty sure that most popular distributions lean towards Python3 (I'm not sure Python(x,y) made the jump, but I'm not sure it's still really alive).

and Python makes side by side installs a pain the ass (I'm looking at you PYTHONPATH, you son of a bitch)
Is it an OS-X issue?

Because it's dead easy on Windows and on Linux. I have both installed on both OS (because students are allowed to code in both, even if all people I know teach Py3k, so I may need to check exotic Python 2 syntaxes I forgot), with a bunch of packages (in two versions), and I haven't had any issue on either.

On Debian, you don't even have to think about it, the modules are stored in directories on a per-version basis (such as /usr/lib/python3.4), and you choose 2 or 3 at installation (be it using aptitude or "manual" install).

On Windows with Conda, not only you can have both, but you can have multiple instances of both using enviromnents (I have 3.4, 3.5 and 3.6 on the same machine). You need to look how it works, but it's quite straightforward. In fact, some version of Pyzo+Conda install both, and you can switch the version in a droplist in the IDE. You can even have both running at the same time.


I admit, each time I had to deal with modules on a OS-X machine, it has been a nightmare (and I've been unable to find a working solution one time out of two), but I thought it was mostly because I wasn't aware of how to do things with OS-X... But once you install a different Python than the one by default, you're fine, though. I'd argue that you WOULD install almost all programming languages, so you can do it too with Python, the one that come with OS-X is just a shortcut for quick scripting...


Not sure if I understand the issue with PYTHONPATH... It's basically a hack, so I can't see it used except on very specific occasions. For example, on Linux, most modules will be installed (so different locations for each version), semi-installed (declared among the modules but not stored into site-packages, same result), or stored in .local/lib/python-version/sites-packages (and again, no chance of version clash).

For example:
Code:
$ echo "print 'py2'" > .local/lib/python2.7/site-packages/mytest.py

$ echo "print('py3k')" > .local/lib/python3.4/site-packages/mytest.py

$ python -c "import mytest"
py2

$ python3 -c "import mytest"
py3k

It's basically the same on Windows, but it depends on the distribution, so... (well, on Linux too, but I was talking about the one in repositories)
 

Koren

Member
Well darn, I guess that would explain me...
Lousy early 1990s.
Late 1980s for me...

I learned programming using a language without function calls (MS Basic 1.0), and a language where I couldn't save (Logo, I still don't understand why the floppy wasn't working)

But I'm still sure I know enough of good programming now ;)


Beside, when I was a teacher assistant with some friends in what is probably the "first" CS engineering school here, there was "good code" in the evaluation grid... we asked the person responsible of the course what "good code" meant exactly, because we found it a bit subjective... He replied "well, code that works". He wasn't even joking. There were a dozen seconds of heavy silence, and even if we probably all began with BASIC, he was virtually killed on the spot, plently of my friends have really strong views about what is "good code".
 
I mentioned it in my post, but osx still has Python 2 as the default and I've heard no rumblings of a change in the immediate future.

As for PYTHONPATH, anything that relies on application specific environment variables is a shit sandwich waiting to be eaten. They make everything more complicated from a configuration standpoint. In practice applications need a particular installation, and if you have two applications that each need a different installation you have to jump through hoops to get them to bind to the correct one because there's only 1 global environment variable
 

Pokemaniac

Member
Does anyone work with selenium ? I have a issue where if I have two windows and one of them closes my program can't detect that it actually closed.

https://i.imgur.com/l8nsPPr.png

I've found it's window handling (particularly short-lived windows) to generally be pretty janky, particularly on Firefox. Fortunately I've been able to get away with just catching exceptions and sort of ignoring stuff when it happens most of the time, but that's not an approach that will work in all cases.
 

Koren

Member
I mentioned it in my post, but osx still has Python 2 as the default and I've heard no rumblings of a change in the immediate future.
Well, they're just behind the times, and I feel they just don't care much about Python...

Though as I said earlier, if you're interested into Python, like any other programming languages, you can download and install it even if there's a basic, default install that doesn't work well...

As for PYTHONPATH, anything that relies on application specific environment variables is a shit sandwich waiting to be eaten.
That's the reason that you shouldn't use PYTHONPATH for modules, but just keep it for quick'n dirty tests, and non-module, version-independant stuff?

In practice applications need a particular installation, and if you have two applications that each need a different installation you have to jump through hoops to get them to bind to the correct one because there's only 1 global environment variable
Well, all Python installations have their specific search path (see PEP-370 for modules), so as long as you stick to the rules, you can't possibly have troubles.

And you can have troubles with a lot of things, I used to have to deal with two versions of the same DLL (there was a fork in FLTK, I needed things in both branches depending on the project), now that was nasty ;)
 

cyborg009

Banned
I've found it's window handling (particularly short-lived windows) to generally be pretty janky, particularly on Firefox. Fortunately I've been able to get away with just catching exceptions and sort of ignoring stuff when it happens most of the time, but that's not an approach that will work in all cases.

Yeah, I run some validation on a window so I can't predict when it closes. But when it does I can go back to the parent window.

I was thinking that maybe I could just alternative between page and check if they exist or if a element does...
 
Top Bottom