Coding: Fleeting Thoughts

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Sat May 28, 2011 8:47 pm UTC

Works just fine in Slackware.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

sheynfinkel
Posts: 12
Joined: Sun May 22, 2011 12:22 am UTC

Re: Coding: Fleeting Thoughts

Postby sheynfinkel » Sat May 28, 2011 8:50 pm UTC

Pepve wrote:I'm presuming you're using a Debian-based distro. I tested it and got the same result. Then i looked at /etc/bash_completion (which is... 1700 lines). I don't really understand what's going on there, but they are doing something special to sudo completion. I think this may be a bug in the sudo handling. Their website has info on reporting bugs.

Yep. It works fine in Arch, just not Debian/Ubuntu. strange...

User avatar
TheChewanater
Posts: 1279
Joined: Sat Aug 08, 2009 5:24 am UTC
Location: lol why am I still wearing a Santa suit?

Re: Coding: Fleeting Thoughts

Postby TheChewanater » Sun May 29, 2011 1:53 pm UTC

I got this message from Valgrid. I don't have much experience with it, but does this mean that there's a leak in my program, or in Glut?

Code: Select all

==732== HEAP SUMMARY:
==732==     in use at exit: 260,044 bytes in 602 blocks
==732==   total heap usage: 3,464 allocs, 2,862 frees, 23,226,164 bytes allocated
==732==
==732== 64 bytes in 1 blocks are definitely lost in loss record 75 of 138
==732==    at 0x402517B: memalign (vg_replace_malloc.c:581)
==732==    by 0x40251D8: posix_memalign (vg_replace_malloc.c:709)
==732==    by 0x4A49D9A: _mesa_align_malloc (in /usr/lib/dri/libdricore.so)
==732==    by 0x4ABC259: _math_matrix_ctr (in /usr/lib/dri/libdricore.so)
==732==    by 0x498F9B8: i915CreateContext (in /usr/lib/dri/i915_dri.so)
==732==    by 0x49A52EB: ??? (in /usr/lib/dri/i915_dri.so)
==732==    by 0x4978122: ??? (in /usr/lib/dri/i915_dri.so)
==732==    by 0x497817D: ??? (in /usr/lib/dri/i915_dri.so)
==732==    by 0x417A665: ??? (in /usr/lib/mesa/libGL.so.1.2)
==732==    by 0x4151929: ??? (in /usr/lib/mesa/libGL.so.1.2)
==732==    by 0x4151BE0: glXCreateNewContext (in /usr/lib/mesa/libGL.so.1.2)
==732==    by 0x4219A03: ??? (in /usr/lib/libglut.so.3.9.0)
==732==
==732== 124 bytes in 1 blocks are definitely lost in loss record 96 of 138
==732==    at 0x4026864: malloc (vg_replace_malloc.c:236)
==732==    by 0x4548902: ??? (in /usr/lib/i386-linux-gnu/libxcb.so.1.1.0)
==732==    by 0x4548A04: ??? (in /usr/lib/i386-linux-gnu/libxcb.so.1.1.0)
==732==    by 0x45483D1: xcb_connect_to_display_with_auth_info (in /usr/lib/i386-linux-gnu/libxcb.so.1.1.0)
==732==    by 0x45485DB: xcb_connect (in /usr/lib/i386-linux-gnu/libxcb.so.1.1.0)
==732==    by 0x442BA22: _XConnectXCB (in /usr/lib/i386-linux-gnu/libX11.so.6.3.0)
==732==    by 0x441B8F3: XOpenDisplay (in /usr/lib/i386-linux-gnu/libX11.so.6.3.0)
==732==    by 0x42128A2: glutInit (in /usr/lib/libglut.so.3.9.0)
==732==    by 0x804ADF4: chewy::ApplicationManager::ApplicationManager(int, char**) (ApplicationManager.cpp:33)
==732==    by 0x8049836: main (main.cpp:101)
==732==
==732== 261 (4 direct, 257 indirect) bytes in 1 blocks are definitely lost in loss record 110 of 138
==732==    at 0x4026864: malloc (vg_replace_malloc.c:236)
==732==    by 0x4212422: fgHintPresent (in /usr/lib/libglut.so.3.9.0)
==732==    by 0x4212D19: glutInit (in /usr/lib/libglut.so.3.9.0)
==732==    by 0x804ADF4: chewy::ApplicationManager::ApplicationManager(int, char**) (ApplicationManager.cpp:33)
==732==    by 0x8049836: main (main.cpp:101)
==732==
==732== 261 (4 direct, 257 indirect) bytes in 1 blocks are definitely lost in loss record 111 of 138
==732==    at 0x4026864: malloc (vg_replace_malloc.c:236)
==732==    by 0x4212422: fgHintPresent (in /usr/lib/libglut.so.3.9.0)
==732==    by 0x4212D4A: glutInit (in /usr/lib/libglut.so.3.9.0)
==732==    by 0x804ADF4: chewy::ApplicationManager::ApplicationManager(int, char**) (ApplicationManager.cpp:33)
==732==    by 0x8049836: main (main.cpp:101)
==732==
==732== 4,140 (2,072 direct, 2,068 indirect) bytes in 1 blocks are definitely lost in loss record 133 of 138
==732==    at 0x4026864: malloc (vg_replace_malloc.c:236)
==732==    by 0x4179B8D: ??? (in /usr/lib/mesa/libGL.so.1.2)
==732==    by 0x417B568: ??? (in /usr/lib/mesa/libGL.so.1.2)
==732==    by 0x415522D: ??? (in /usr/lib/mesa/libGL.so.1.2)
==732==    by 0x415156E: glXGetFBConfigs (in /usr/lib/mesa/libGL.so.1.2)
==732==    by 0x41527D2: glXChooseFBConfig (in /usr/lib/mesa/libGL.so.1.2)
==732==    by 0x4219C75: fgChooseFBConfig (in /usr/lib/libglut.so.3.9.0)
==732==    by 0x4219F0F: fgOpenWindow (in /usr/lib/libglut.so.3.9.0)
==732==    by 0x4218A8C: fgCreateWindow (in /usr/lib/libglut.so.3.9.0)
==732==    by 0x421A4E4: glutCreateWindow (in /usr/lib/libglut.so.3.9.0)
==732==    by 0x804AE23: chewy::ApplicationManager::ApplicationManager(int, char**) (ApplicationManager.cpp:36)
==732==    by 0x8049836: main (main.cpp:101)
==732==
==732== LEAK SUMMARY:
==732==    definitely lost: 2,268 bytes in 5 blocks
==732==    indirectly lost: 2,582 bytes in 15 blocks
==732==      possibly lost: 0 bytes in 0 blocks
==732==    still reachable: 255,194 bytes in 582 blocks
==732==         suppressed: 0 bytes in 0 blocks
ImageImage
http://internetometer.com/give/4279
No one can agree how to count how many types of people there are. You could ask two people and get 10 different answers.

Osha
Posts: 727
Joined: Wed Dec 03, 2008 3:24 am UTC
Location: Boise, Idaho, USA

Re: Coding: Fleeting Thoughts

Postby Osha » Mon May 30, 2011 8:04 am UTC

Without having worked much with glut I can't say. Valgrind comes with some built-in error suppression, but only for libraries it knows about. For other libraries valgrind picks up these sorts of errors all the friggin' time.
What I would do is read up on writing valgrind supression files, and then: if you're feeling motivated... create a test project that you're relatively confident doesn't leak (on your part at least) for every glut error that valgrind reports, hand-tailing suppressions for each one, and repeating until there are no more. OR if you're lazy like me, write a few very generic glut suppression entries just to get valgrind out of my hair.

From a quick google search, the "--track-origins" flag might also help in general determine if it's your code at fault, or a (hopefully) false in a library, when you run into stuff like this.

User avatar
TheChewanater
Posts: 1279
Joined: Sat Aug 08, 2009 5:24 am UTC
Location: lol why am I still wearing a Santa suit?

Re: Coding: Fleeting Thoughts

Postby TheChewanater » Mon May 30, 2011 6:26 pm UTC

FT: I can't believe this abomination actually compiles and runs...

Code: Select all

#include "stdio.h"
#include "stdlib.h"

void foo (void* whatever, ...) {}

void bar (int a, int b)
{
    printf ("%d+%d=%d\n", a, b, a + b);
    
    exit 
(0);
}

int 
main 
()
{
    foo (0, 23, 49);
    goto *(void*)(&bar);
    
    return 0
;
}
 
ImageImage
http://internetometer.com/give/4279
No one can agree how to count how many types of people there are. You could ask two people and get 10 different answers.

User avatar
Robert'); DROP TABLE *;
Posts: 730
Joined: Mon Sep 08, 2008 6:46 pm UTC
Location: in ur fieldz

Re: Coding: Fleeting Thoughts

Postby Robert'); DROP TABLE *; » Mon May 30, 2011 8:57 pm UTC

I thought the compiler wasn't supposed to let you dereference void*. Or is that something more arcane?
...And that is how we know the Earth to be banana-shaped.

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Coding: Fleeting Thoughts

Postby EvanED » Mon May 30, 2011 9:13 pm UTC

Robert'); DROP TABLE *; wrote:I thought the compiler wasn't supposed to let you dereference void*. Or is that something more arcane?

See this GCC extension.

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Tue May 31, 2011 1:05 am UTC

EvanED wrote:
Robert'); DROP TABLE *; wrote:I thought the compiler wasn't supposed to let you dereference void*. Or is that something more arcane?

See this GCC extension.


That's quite scary.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
TheChewanater
Posts: 1279
Joined: Sat Aug 08, 2009 5:24 am UTC
Location: lol why am I still wearing a Santa suit?

Re: Coding: Fleeting Thoughts

Postby TheChewanater » Tue May 31, 2011 1:45 am UTC

I think I've just written the least-portable C code possible that doesn't use asm().

Compiled on GCC 4.6.0, default settings, on Ubuntu 11.04.

Code: Select all

#include "stdio.h"

void
foo 
()
{
    printf ("Didn't work.\n");
    printf ("It worked!\n");
}

int 
main 
(int argc, char *argv[])
{
    goto *((void*)&foo + 13);
}
 
ImageImage
http://internetometer.com/give/4279
No one can agree how to count how many types of people there are. You could ask two people and get 10 different answers.

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Coding: Fleeting Thoughts

Postby EvanED » Tue May 31, 2011 1:47 am UTC

I wouldn't be surprised if that's less portable than using asm.

User avatar
Robert'); DROP TABLE *;
Posts: 730
Joined: Mon Sep 08, 2008 6:46 pm UTC
Location: in ur fieldz

Re: Coding: Fleeting Thoughts

Postby Robert'); DROP TABLE *; » Thu Jun 02, 2011 3:02 pm UTC

According to Google, nobody has ever tried tweening in C#. Am I doing something terribly wrong?
...And that is how we know the Earth to be banana-shaped.

forgotwassorry
Posts: 1
Joined: Sat Jun 04, 2011 12:45 pm UTC

Re: Coding: Fleeting Thoughts

Postby forgotwassorry » Sat Jun 04, 2011 2:15 pm UTC

Who needs realloc?

Code: Select all

int main()
{
    int *a, b; a = &b - 1;
   
    int c[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
    {
        int i;
        for (i = 0; i > -10; i--) {
            printf("%d ", a[i]);
        }
        printf("\n");
    }
   
    int d[] = {20, 19, 18, 17, 16, 15, 14, 13, 12, 11};
    {
        int i;
        for (i = 0; i > -20; i--) {
            printf("%d ", a[i]);
        }
        printf("\n");
    }
   
    int e[] = {30, 29, 28, 27, 26, 25, 24, 23, 22, 21};
    {
        int i;
        for (i = 0; i > -30; i--) {
            printf("%d ", a[i]);
        }
        printf("\n");
    }
   
    return 0;
}


I'm wondering how unportable this actually is. Can someone find a compiler/machine this won't work with?

User avatar
Steax
SecondTalon's Goon Squad
Posts: 3038
Joined: Sat Jan 12, 2008 12:18 pm UTC

Re: Coding: Fleeting Thoughts

Postby Steax » Sat Jun 04, 2011 3:56 pm UTC

"Remember me" login PHP code.

I used to go with the generate-a-server-salt-and-give-that-as-a-cookie route, but that seems dangerous, unless I use HTTPS on every page. It seems scary to transfer it on every request. What's the general alternative? (I guess that doesn't make much difference when people can just sniff the session cookie, but...)

... So does that mean I should just blame sniffing on users? It seems like a huge hassle to get around. Or maybe an impossible one.
In Minecraft, I use the username Rirez.

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Sat Jun 04, 2011 4:09 pm UTC

Steax wrote:"Remember me" login PHP code.

I used to go with the generate-a-server-salt-and-give-that-as-a-cookie route, but that seems dangerous, unless I use HTTPS on every page. It seems scary to transfer it on every request. What's the general alternative? (I guess that doesn't make much difference when people can just sniff the session cookie, but...)

... So does that mean I should just blame sniffing on users? It seems like a huge hassle to get around. Or maybe an impossible one.


If you associate the "persistent session" with an IP address, so that it does not matter if the session id gets intercepted? If the IP has been changed, you can just throw up an "oh, it seems you're visiting us from a new location, for security*, please log in again"-screen.

* for once, a "for security" claim that isn't bullshit.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

Ubik
Posts: 1016
Joined: Thu Oct 18, 2007 3:43 pm UTC

Re: Coding: Fleeting Thoughts

Postby Ubik » Sat Jun 04, 2011 4:16 pm UTC

IP address isn't a reliable identifier at all. There can be all kinds of NAT or proxy things going on so it isn't a one per user thing.

User avatar
Steax
SecondTalon's Goon Squad
Posts: 3038
Joined: Sat Jan 12, 2008 12:18 pm UTC

Re: Coding: Fleeting Thoughts

Postby Steax » Sat Jun 04, 2011 5:21 pm UTC

Sadly, that won't work because my country's main ISP applies dynamic IP addresses to most users, so practically everyone will have to log in again if they shut down their modem or go idle for more than x hours (they auto-disconnect for some reason, and it's not my hardware). For most cases it would make the feature pointless in the first place.

I guess I'll just have to warn users about logging in from a public wifi or something. =/
In Minecraft, I use the username Rirez.

User avatar
hotaru
Posts: 1045
Joined: Fri Apr 13, 2007 6:54 pm UTC

Re: Coding: Fleeting Thoughts

Postby hotaru » Sat Jun 04, 2011 8:27 pm UTC

Steax wrote:What's the general alternative?

you could roll your own public key authentication in javascript or something, but just using https for everything would be a lot easier. is there any real reason not to use https?

Code: Select all

factorial product enumFromTo 1
isPrime n 
factorial (1) `mod== 1

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6598
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Sun Jun 05, 2011 12:10 am UTC

Steax wrote:"Remember me" login PHP code.

I used to go with the generate-a-server-salt-and-give-that-as-a-cookie route, but that seems dangerous, unless I use HTTPS on every page. It seems scary to transfer it on every request. What's the general alternative? (I guess that doesn't make much difference when people can just sniff the session cookie, but...)

... So does that mean I should just blame sniffing on users? It seems like a huge hassle to get around. Or maybe an impossible one.


You can send two cookies, one with a secure flag sent that is only sent over HTTPS connections, and one that is for all connections. Your login page requires HTTPS, and when they log in you send both cookies. Your regular bullshit pages with nothing sensitive just checks the regular token, and any page that has sensitive data (e.g. change password page) checks the secure token. That can be used for many websites, at least. In some cases, like banks, you really do want everything to be HTTPS no matter what.

hotaru wrote: is there any real reason not to use https?


If you have a high traffic website, the additional performance hit of https can be noticeable. Also, browsers typically don't use the disk cache for HTTPS content (although they will use memory cache), so that could result in an increase of requests for static content which can be a small performance hit and potentially a large bandwidth hit.
Summum ius, summa iniuria.

User avatar
phlip
Restorer of Worlds
Posts: 7573
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: Coding: Fleeting Thoughts

Postby phlip » Sun Jun 05, 2011 1:10 am UTC

Say you're in an Internet cafe with unsecured wireless, connecting to the Internet via NAT. Someone connects to some non-SSL site, which automatically logs in via some "remember me" mechanism. You capture the HTTP request, and send it yourself. There is literally nothing the server can use to distinguish the two requests... the contents are identical, the source IPs are identical... sure, one of them came first and the other came second, but that doesn't help much, as the attacker could easily predict what the *next* request from the real user would be, and get in first.

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Coding: Fleeting Thoughts

Postby EvanED » Sun Jun 05, 2011 2:02 am UTC

Thesh wrote:If you have a high traffic website, the additional performance hit of https can be noticeable. Also, browsers typically don't use the disk cache for HTTPS content (although they will use memory cache), so that could result in an increase of requests for static content which can be a small performance hit and potentially a large bandwidth hit.

Not only your browser, but intermediate caches at your ISP and such also will also not apply.

User avatar
Steax
SecondTalon's Goon Squad
Posts: 3038
Joined: Sat Jan 12, 2008 12:18 pm UTC

Re: Coding: Fleeting Thoughts

Postby Steax » Sun Jun 05, 2011 5:11 am UTC

Thesh wrote:You can send two cookies, one with a secure flag sent that is only sent over HTTPS connections, and one that is for all connections. Your login page requires HTTPS, and when they log in you send both cookies. Your regular bullshit pages with nothing sensitive just checks the regular token, and any page that has sensitive data (e.g. change password page) checks the secure token. That can be used for many websites, at least. In some cases, like banks, you really do want everything to be HTTPS no matter what.


I wasn't aware this was possible. I'll go with that, then - I totally missed the 'secure' option in setcookie(). Does this mean the browser won't send it over the network when it's not over HTTPS at all? (it would defeat the purpose if it still got sent, no?)

I tested going full-HTTPS but the performance impact was a cause for concern. How do most sites, like forums do this? It would be ridiculously easy to catch anyone's session if they connect on an unsecured wireless, wouldn't it? I guess it's a matter of is-it-worth-stealing-someone's-account-to-post-cat-pictures-vs-getting-your-own-damn-work-done thing.
In Minecraft, I use the username Rirez.

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6598
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Sun Jun 05, 2011 6:31 pm UTC

Steax wrote: Does this mean the browser won't send it over the network when it's not over HTTPS at all? (it would defeat the purpose if it still got sent, no?)


Correct, the browser won't send cookies that have the secure flag set, over an unsecured connection.

Steax wrote:I tested going full-HTTPS but the performance impact was a cause for concern. How do most sites, like forums do this? It would be ridiculously easy to catch anyone's session if they connect on an unsecured wireless, wouldn't it? I guess it's a matter of is-it-worth-stealing-someone's-account-to-post-cat-pictures-vs-getting-your-own-damn-work-done thing.


Most places don't use the secure flag and you can usually steal the cookie if they are using unsecured wireless. Most forums and websites where there isn't really anything to steal don't even use HTTPS. Places like banks, and many major websites that take security seriously (e.g. Gmail) have everything HTTPS. Amazon.com has a cookie with the secure flag set, although many online stores do not do that.
Summum ius, summa iniuria.

userxp
Posts: 436
Joined: Thu Jul 09, 2009 12:40 pm UTC

Re: Coding: Fleeting Thoughts

Postby userxp » Wed Jun 08, 2011 11:15 pm UTC

Javascript efficiency has been increasing dramatically thanks to the second browser wars. Current browsers actually compile Javascript code to native code. A simple loop (tested using this) on Opera 11.10 seems to run about 100 times faster than in Python 2.7.1.

If this trend continues, we might have to start thinking about building local applications in Javascript.

User avatar
Sc4Freak
Posts: 673
Joined: Thu Jul 12, 2007 4:50 am UTC
Location: Redmond, Washington

Re: Coding: Fleeting Thoughts

Postby Sc4Freak » Thu Jun 09, 2011 12:33 am UTC

userxp wrote:Javascript efficiency has been increasing dramatically thanks to the second browser wars. Current browsers actually compile Javascript code to native code. A simple loop (tested using this) on Opera 11.10 seems to run about 100 times faster than in Python 2.7.1.

If this trend continues, we might have to start thinking about building local applications in Javascript.

I certainly hope not. This is the plan Microsoft has for Windows 8 and frankly, I have no idea why you would use Javascript if you had a choice. Javascript is a horrifyingly bad language - the only reason it's gained popularity on the web is because you have no other choice. The whole HTML5+JS movement is great for the web, but it makes absolutely zero sense for local applications. Not only is Javascript a terrible language, it's also missing support for critical features required for local apps - things like local filesystem support, access to the registry, and the ability to call down into native operating system APIs. Not to mention, HTML and CSS are practically useless for layout of a UI. How long did it take people to figure out how to do a two-column layout in CSS? Compared to modern toolkits and languages we have for local applications, HTML5/CSS/JS are like using stone tools. They're fine for the web, but hopelessly inadequate for all but the most trivial local applications.

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Coding: Fleeting Thoughts

Postby EvanED » Thu Jun 09, 2011 1:28 am UTC

Sc4Freak wrote:I certainly hope not. This is the plan Microsoft has for Windows 8 and frankly, I have no idea why you would use Javascript if you had a choice. Javascript is a horrifyingly bad language - the only reason it's gained popularity on the web is because you have no other choice. The whole HTML5+JS movement is great for the web, but it makes absolutely zero sense for local applications. Not only is Javascript a terrible language, it's also missing support for critical features required for local apps - things like local filesystem support, access to the registry, and the ability to call down into native operating system APIs. Not to mention, HTML and CSS are practically useless for layout of a UI. How long did it take people to figure out how to do a two-column layout in CSS? Compared to modern toolkits and languages we have for local applications, HTML5/CSS/JS are like using stone tools. They're fine for the web, but hopelessly inadequate for all but the most trivial local applications.

I agree with you, but I think you overstate things on a couple points. For instance, CSS: Qt uses CSS for styling widgets, and while it's not using it for layout (maybe?), it is pretty spiffy. And it's not like accessing OS concepts is anything more than saying "oh, this implementation supports these extra API functions." I wouldn't be surprised if these things existed now. While I definitely cringe at the thought of writing applications in JavaScript, it's also not the worst language out there by any means...

Maelstrom.
Posts: 76
Joined: Tue Oct 21, 2008 12:18 pm UTC

Re: Coding: Fleeting Thoughts

Postby Maelstrom. » Thu Jun 09, 2011 1:37 am UTC

EvanED wrote:
Sc4Freak wrote:I certainly hope not. This is the plan Microsoft has for Windows 8 and frankly, I have no idea why you would use Javascript if you had a choice. Javascript is a horrifyingly bad language - the only reason it's gained popularity on the web is because you have no other choice. The whole HTML5+JS movement is great for the web, but it makes absolutely zero sense for local applications. Not only is Javascript a terrible language, it's also missing support for critical features required for local apps - things like local filesystem support, access to the registry, and the ability to call down into native operating system APIs. Not to mention, HTML and CSS are practically useless for layout of a UI. How long did it take people to figure out how to do a two-column layout in CSS? Compared to modern toolkits and languages we have for local applications, HTML5/CSS/JS are like using stone tools. They're fine for the web, but hopelessly inadequate for all but the most trivial local applications.

I agree with you, but I think you overstate things on a couple points. For instance, CSS: Qt uses CSS for styling widgets, and while it's not using it for layout (maybe?), it is pretty spiffy. And it's not like accessing OS concepts is anything more than saying "oh, this implementation supports these extra API functions." I wouldn't be surprised if these things existed now. While I definitely cringe at the thought of writing applications in JavaScript, it's also not the worst language out there by any means...

May I point out Node.js. It is a JavaScript environment designed to run on a server or other non-browser based systems. It has support for interacting with the filesystem, with low level network protocols, the operating system and its processes. It provides a very simple module system for loading other modules, such as database connectivity, image processing, and GUI toolkits (I have heard similarities drawn between Node.js modules and Pythons module system, although I can not comment upon these similarities).

What Sc4Freak is mostly complaining about seems to be the lack of ability to do anything external to the browser, not so much the language itself. The language itself is (in my opinion) quite a nice one. The environment of running JavaScript in the browser is limiting, annoying, frustrating, and fraught with browser compatibility issues. Node.js removes these problems, allowing you to use JavaScript in a sane environment with similar tools and modules available to you that are in most other modern languages and environments.

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Coding: Fleeting Thoughts

Postby EvanED » Thu Jun 09, 2011 1:47 am UTC

Maelstrom. wrote:The language itself is (in my opinion) quite a nice one.

Ugh. My opinion on JavaScript is pretty much summed up by the image I usually bring out for this:
Spoiler:
Image
.

To some extent that's true of nearly all languages, but I feel the balance is a bit more against JS than most. I think I'd use C++ before JavaScript, and my relation with even that is very... love/hate, and I don't think it should be used for most programs nowadays.

But anyway, this is more a topic for religious wars...

User avatar
Sc4Freak
Posts: 673
Joined: Thu Jul 12, 2007 4:50 am UTC
Location: Redmond, Washington

Re: Coding: Fleeting Thoughts

Postby Sc4Freak » Thu Jun 09, 2011 4:25 am UTC

EvanED wrote:While I definitely cringe at the thought of writing applications in JavaScript, it's also not the worst language out there by any means...

You're right, Javascript is probably second to PHP in terms of painfulness. :P

elminster
Posts: 1560
Joined: Mon Feb 26, 2007 1:56 pm UTC
Location: London, UK, Dimensions 1 to 42.
Contact:

Re: Coding: Fleeting Thoughts

Postby elminster » Thu Jun 09, 2011 5:41 am UTC

C++ has a wide spectrum of potential pain, it can be ungodly painful because you can break it in such novel, obscure, and complicated ways; can basically all be avoided though.

Html + css for client side apps is a bad idea. Take adobe AIR for example... it's terrible (Slow as hell considering what it does) and pointless to use unless your abilities are limited to html/css. There's plenty of good gui frameworks for plenty of languages.

Some function/method naming in PHP is just weird.
Image

Pepve
Posts: 57
Joined: Wed Jul 28, 2010 9:47 am UTC

Re: Coding: Fleeting Thoughts

Postby Pepve » Thu Jun 09, 2011 9:46 am UTC

Maelstrom. wrote:May I point out Node.js. It is a JavaScript environment designed to run on a server or other non-browser based systems. It has support for interacting with the filesystem, with low level network protocols, the operating system and its processes. It provides a very simple module system for loading other modules, such as database connectivity, image processing, and GUI toolkits (I have heard similarities drawn between Node.js modules and Pythons module system, although I can not comment upon these similarities).

What Sc4Freak is mostly complaining about seems to be the lack of ability to do anything external to the browser, not so much the language itself. The language itself is (in my opinion) quite a nice one. The environment of running JavaScript in the browser is limiting, annoying, frustrating, and fraught with browser compatibility issues. Node.js removes these problems, allowing you to use JavaScript in a sane environment with similar tools and modules available to you that are in most other modern languages and environments.

I second this. The past few weeks i've been using Node for some simple command line tools and shell one-liners. It's quite nice. (I was working with CouchDB, so using JavaScript made sense, too.)

User avatar
Steax
SecondTalon's Goon Squad
Posts: 3038
Joined: Sat Jan 12, 2008 12:18 pm UTC

Re: Coding: Fleeting Thoughts

Postby Steax » Fri Jun 10, 2011 6:42 am UTC

I'm actually quite fond of Javascript. I used to use the Sphere game engine to make games in it. It certainly doesn't have the toughness you'd see in, say, C++ or PHP, but it gets the job done. Browser/DOM Javascript is a pain in the rear, which is why stuff like jQuery exists.

FT: I wonder how many people would use a "lost password; send to twitter DM" feature vs a send-to-email one. Time to test.
In Minecraft, I use the username Rirez.

User avatar
TheChewanater
Posts: 1279
Joined: Sat Aug 08, 2009 5:24 am UTC
Location: lol why am I still wearing a Santa suit?

Re: Coding: Fleeting Thoughts

Postby TheChewanater » Fri Jun 10, 2011 7:05 pm UTC

Steax wrote:FT: I wonder how many people would use a "lost password; send to twitter DM" feature vs a send-to-email one. Time to test.

Both of those are terrible ideas, since they require storing the password as plain text.
ImageImage
http://internetometer.com/give/4279
No one can agree how to count how many types of people there are. You could ask two people and get 10 different answers.

User avatar
Xeio
Friends, Faidites, Countrymen
Posts: 5101
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\
Contact:

Re: Coding: Fleeting Thoughts

Postby Xeio » Fri Jun 10, 2011 7:14 pm UTC

TheChewanater wrote:
Steax wrote:FT: I wonder how many people would use a "lost password; send to twitter DM" feature vs a send-to-email one. Time to test.
Both of those are terrible ideas, since they require storing the password as plain text.
Well, in a secure system these can still be available, you can usually "recover password" which involves being given a new password (so the old hash is wiped out).

User avatar
Steax
SecondTalon's Goon Squad
Posts: 3038
Joined: Sat Jan 12, 2008 12:18 pm UTC

Re: Coding: Fleeting Thoughts

Postby Steax » Fri Jun 10, 2011 10:15 pm UTC

Yeah, I mean the usual send-me-a-link-to-generate-a-new-password method, just sent via a twitter DM instead of email. Interesting how it coincides with a twitter security problem which allows third parties to access DMs... Uh.
In Minecraft, I use the username Rirez.

Derek
Posts: 2181
Joined: Wed Aug 18, 2010 4:15 am UTC

Re: Coding: Fleeting Thoughts

Postby Derek » Sun Jun 12, 2011 10:42 am UTC

TheChewanater wrote:I think I've just written the least-portable C code possible that doesn't use asm().

Compiled on GCC 4.6.0, default settings, on Ubuntu 11.04.

Spoiler:

Code: Select all

#include "stdio.h"

void
foo 
()
{
    printf ("Didn't work.\n");
    printf ("It worked!\n");
}

int 
main 
(int argc, char *argv[])
{
    goto *((void*)&foo + 13);
}
 

forgotwassorry wrote:Who needs realloc?
Spoiler:

Code: Select all

int main()
{
    int *a, b; a = &b - 1;
   
    int c[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
    {
        int i;
        for (i = 0; i > -10; i--) {
            printf("%d ", a[i]);
        }
        printf("\n");
    }
   
    int d[] = {20, 19, 18, 17, 16, 15, 14, 13, 12, 11};
    {
        int i;
        for (i = 0; i > -20; i--) {
            printf("%d ", a[i]);
        }
        printf("\n");
    }
   
    int e[] = {30, 29, 28, 27, 26, 25, 24, 23, 22, 21};
    {
        int i;
        for (i = 0; i > -30; i--) {
            printf("%d ", a[i]);
        }
        printf("\n");
    }
   
    return 0;
}


I'm wondering how unportable this actually is. Can someone find a compiler/machine this won't work with?

Both work on windows with gcc/mingw. Though with regards to the first, I think "&foo + 13" may as well count as assembly.

Incidentally, it is also a bad idea to leave your forkbomb named as "test.exe".


Lastly, with regards to the Javascript discussion, from my (admittedly limited) experience with it, it was actually quite nice. Then again, I also thought PHP was pretty good too (at least for what its meant to do), so I may be a freak.

User avatar
tes
Posts: 56
Joined: Thu Nov 12, 2009 5:35 pm UTC

Re: Coding: Fleeting Thoughts

Postby tes » Sun Jun 12, 2011 6:49 pm UTC

I'm new to programming, and during one of my first projects, I came across this: If you have three classes A, B and C in C++, and A has instances of B and C, how would you go about the problem that B needs to be able to access member variables/functions of C? At the moment my solution is to let B have a pointer to the instance of C. It works, but it feels very ... clumsy (then again maybe it's just my implementation that is clumsy).

User avatar
TheChewanater
Posts: 1279
Joined: Sat Aug 08, 2009 5:24 am UTC
Location: lol why am I still wearing a Santa suit?

Re: Coding: Fleeting Thoughts

Postby TheChewanater » Sun Jun 12, 2011 7:25 pm UTC

You could pass the instance of C to B's methods when it needs it.

For example,

Code: Select all

void A::foo ()
{
  
this->b.do_something (this->c);
ImageImage
http://internetometer.com/give/4279
No one can agree how to count how many types of people there are. You could ask two people and get 10 different answers.

User avatar
tes
Posts: 56
Joined: Thu Nov 12, 2009 5:35 pm UTC

Re: Coding: Fleeting Thoughts

Postby tes » Sun Jun 12, 2011 11:49 pm UTC

Thanks, I hadn't thought of that. But it's probably not the best way to do it if B needs C for basically everything it does, is it?

User avatar
TheChewanater
Posts: 1279
Joined: Sat Aug 08, 2009 5:24 am UTC
Location: lol why am I still wearing a Santa suit?

Re: Coding: Fleeting Thoughts

Postby TheChewanater » Mon Jun 13, 2011 12:50 am UTC

Does A really need C? You could make A have B, and B have C.
ImageImage
http://internetometer.com/give/4279
No one can agree how to count how many types of people there are. You could ask two people and get 10 different answers.

User avatar
tes
Posts: 56
Joined: Thu Nov 12, 2009 5:35 pm UTC

Re: Coding: Fleeting Thoughts

Postby tes » Mon Jun 13, 2011 10:09 pm UTC

Unfortunately, C also needs B a lot (I oversimplified that away, sorry). A is a Game class, which consists of several turns, which are represented by instances of C. The players are B.


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 10 guests