d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Make Me A Better Programmer - From Step 1
Prev1323334353656Next
Add Reply New Topic New Poll
Member
Posts: 11,637
Joined: Feb 2 2004
Gold: 434.84
Mar 1 2014 02:57pm
Quote (AbDuCt @ Mar 1 2014 03:00pm)
I just recently updated to ruby 2.0 after they finally hit the p4xx release and announced that 1.9.3 is no longer industry standard and will lose support in except for security fixes later in 2014, and will be discontinued all together in 2015. Mean while I finally decided to install Rails. It's pretty sexy, but Rails is pretty confusing up front. You have so many views and controllers and database shit you have to create. Just to create a simple page to output "hello world" it requires you to create a welcome controller with a #index action, a welcome index.html.erb view to display your hello world, and then change the routes to redirect / "root" to /welcome/index.

I can see how it makes creating large database sites easy though, must be why so many high profile websites ditched php and went to rails, such as twitter, hulu, justin.tv, urban dictonary, github, ect.


Yeah, that's exactly why Rails and Django (for Python) are so popular. When you are trying to put together a full stack site from the ground up those tools are great for getting the ball rolling and not having to worry about the minutiae of all the different, individual frameworks for templating, persistence, etc. It makes life a lot easier. For making smaller web apps it can be incredibly disorienting because the amount of activation energy needed to get any project of any size started is exactly the same. Another problem with PHP is that it tries to be a lot of different things while somehow managing to be good at none of them.

I'm not sure what's out there for Ruby but Python has smaller "micro" frameworks like Flask that give you a lot of what Rails has to offer without the bulk of having a persistence layer that you may not need. There must be a similar web framework for Ruby. If you aren't opposed to Scala the Play framework is also quite good and it doesn't have bulk that Rails does.
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Mar 1 2014 03:03pm
Quote (rockonkenshin @ Mar 1 2014 04:57pm)
Yeah, that's exactly why Rails and Django (for Python) are so popular. When you are trying to put together a full stack site from the ground up those tools are great for getting the ball rolling and not having to worry about the minutiae of all the different, individual frameworks for templating, persistence, etc. It makes life a lot easier. For making smaller web apps it can be incredibly disorienting because the amount of activation energy needed to get any project of any size started is exactly the same. Another problem with PHP is that it tries to be a lot of different things while somehow managing to be good at none of them.

I'm not sure what's out there for Ruby but Python has smaller "micro" frameworks like Flask that give you a lot of what Rails has to offer without the bulk of having a persistence layer that you may not need. There must be a similar web framework for Ruby. If you aren't opposed to Scala the Play framework is also quite good and it doesn't have bulk that Rails does.


I'm just learning rails for the sake of something new to do. I will also check out the gem repo to see if there are any more lightweight frameworks. One thing I like about rails though is that it has built in features the user doesn't even need to activate such as cross site scripting attack prevention and semi tamper proof POST variable parsing (doesn't allow a controller to accept post variables unless you specifically permit them as well as add rules to permit specific types (length of string, integer only, ect). Not to mention that rails makes data basing extremely easy.

This post was edited by AbDuCt on Mar 1 2014 03:05pm
Member
Posts: 11,637
Joined: Feb 2 2004
Gold: 434.84
Mar 1 2014 03:06pm
Quote (AbDuCt @ Mar 1 2014 04:03pm)
I'm just learning rails for the sake of something new to do. I will also check out the gem repo to see if there are any more lightweight frameworks. One thing I like about rails though is that it has built in features the user doesn't even need to activate such as cross site scripting attack prevention and semi tamper proof POST variable parsing (doesn't allow a controller to accept post variables unless you specifically permit them as well as add rules to permit specific types (length of string, integer only, ect).


Yeah that stuff is quite nice. I recently worked on a rather large project that involved making heavy changes to a Groovy/Grails application and having that stuff right out of the box was awesome.
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Mar 3 2014 12:37am
Quote (HighschoolTurd @ Feb 28 2014 10:50pm)
Looks like your professor is trying to re-invent the wheel.


How so?

Also, how would you teach those concepts instead?

It was a rough ride and a simple project but the ideas were a little more complex than usual.

This post was edited by Eep on Mar 3 2014 12:37am
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Mar 3 2014 12:50am
Quote (Eep @ Mar 3 2014 01:37am)

Also, how would you teach those concepts instead?


Ding ding ding! We have a winner!
Member
Posts: 24,488
Joined: Jul 11 2011
Gold: 1,272.50
Mar 3 2014 01:06am
Quote (rockonkenshin @ 1 Mar 2014 13:57)
Another problem with PHP is that it tries tobe a lot of different things while somehow managing to be good at none of them.


Like? Example?

This post was edited by HighschoolTurd on Mar 3 2014 01:07am
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Mar 3 2014 01:06am
Quote (Eep @ Mar 3 2014 02:37am)
Also, how would you teach those concepts instead?


It's simple.... we kill the batman.

Quote (HighschoolTurd @ Mar 3 2014 03:06am)
Like?


Security LOL. Incoming before preg_replace code exec exploit blabbering.

This post was edited by AbDuCt on Mar 3 2014 01:07am
Member
Posts: 24,488
Joined: Jul 11 2011
Gold: 1,272.50
Mar 3 2014 01:10am
Quote (AbDuCt @ 3 Mar 2014 00:06)
Security.



That sounds like a personal coding problem. PHP can be just fine if the person knows how to secure it.

This post was edited by HighschoolTurd on Mar 3 2014 01:11am
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Mar 3 2014 01:24am
Quote (HighschoolTurd @ Mar 3 2014 03:10am)
That sounds like a personal coding problem. PHP can be just fine if the person knows how to secure it.


Which is why the function itself is flawed. Because it is my problem. Nice one LOL.
Member
Posts: 11,637
Joined: Feb 2 2004
Gold: 434.84
Mar 3 2014 07:13am
Quote (HighschoolTurd @ Mar 3 2014 02:10am)
That sounds like a personal coding problem. PHP can be just fine if the person knows how to secure it.


The problem is that instead of having security baked in by default you need to go out of your way to make sure everything is secure. This is bad design and only shitty programmers and/or idiots want features to be more obscure and harder to configure.

Quote (HighschoolTurd @ Mar 3 2014 02:06am)
Like? Example?


This guy nails it: http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/

He cites these points as hallmarks of a well-designed language:

Quote (veekun)

A language must be predictable. It’s a medium for expressing human ideas and having a computer execute them, so it’s critical that a human’s understanding of a program actually be correct.
A language must be consistent. Similar things should look similar, different things different. Knowing part of the language should aid in learning and understanding the rest.
A language must be concise. New languages exist to reduce the boilerplate inherent in old languages. (We could all write machine code.) A language must thus strive to avoid introducing new boilerplate of its own.
A language must be reliable. Languages are tools for solving problems; they should minimize any new problems they introduce. Any “gotchas” are massive distractions.
A language must be debuggable. When something goes wrong, the programmer has to fix it, and we need all the help we can get.


PHP in some major way on all five points. Some examples of really mind-bendingly stupid design:

Quote (veekun)

Weak typing (i.e., silent automatic conversion between strings/numbers/et al) is so complex that whatever minor programmer effort is saved is by no means worth it.
...
For the same reason, "6" == " 6", "4.2" == "4.20", and "133" == "0133". But note that 133 != 0133, because 0133 is octal. But "0x10" == "16" and "1e3" == "1000"!

...
0x0+2 produces 4. The parser considers the 2 as both part of the hex literal and a separate decimal literal, treating this as 0x002 + 2. 0x0+0x2 displays the same problem. Strangely, 0x0 +2 is still 4, but 0x0+ 2 is correctly 2. (This is fixed in PHP 5.4. But it’s also re-broken in PHP 5.4, with the new 0b literal prefix: 0b0+1 produces 2.)


Weak typing is good in many ways. Weak typing with simple implicit conversion *can* be ok. Weak typing with incredibly complicated implicit conversion that may or may not work because the PHP developers love to regress bugs? That's really bad design and encourages programming mistakes.

Since a language should be predictable, this shouldn't be there:

Quote (veekun)

There is a whole lot of action at a distance. Consider this code, taken from the PHP docs somewhere.

  @fopen('http://example.com/not-existing-file', 'r');
What will it do?

If PHP was compiled with --disable-url-fopen-wrapper, it won’t work. (Docs don’t say what “won’t work” means; returns null, throws exception?) Note that this flag was removed in PHP 5.2.5.
If allow_url_fopen is disabled in php.ini, this still won’t work. (How? No idea.)
Because of the @, the warning about the non-existent file won’t be printed.
But it will be printed if scream.enabled is set in php.ini.
Or if scream.enabled is set manually with ini_set.
But not if the right error_reporting level isn’t set.
If it is printed, exactly where it goes depends on display_errors, again in php.ini. Or ini_set.
I can’t tell how this innocuous function call will behave without consulting compile-time flags, server-wide configuration, and configuration done in my program. And this is all built in behavior.


The fuck? Also '@' is a PHP operator (stolen from DOS, which isn't the first place I would take programming hints from) and that will silence thrown errors. Oh, but if you don't use that and get an error you may not ever see unless you set up a global handler for it. That's incredibly stupid and the only thing it would do is waste my time setting something up that should just be the default.

On to operators! Those should just work, right? I mean how could anyone fuck up equality?

Quote (veekun)

== is useless.
It’s not transitive. "foo" == TRUE, and "foo" == 0… but, of course, TRUE != 0.
== converts to numbers when possible (123 == "123foo"… although "123" != "123foo"), which means it converts to floats when possible. So large hex strings (like, say, password hashes) may occasionally compare true when they’re not. Even JavaScript doesn’t do this.
For the same reason, "6" == " 6", "4.2" == "4.20", and "133" == "0133". But note that 133 != 0133, because 0133 is octal. But "0x10" == "16" and "1e3" == "1000"!
=== compares values and type… except with objects, where === is only true if both operands are actually the same object! For objects, == compares both value (of every attribute) and type, which is what === does for every other type


That is atrocious. Object/primitive equality being transitive is like language design 101. How could you possibly fuck that up? Oh wait, it's incredibly easy because of the insane weak typing system and bad developers.

Here's another gem:

Quote (veekun)

Unlike (literally!) every other language with a similar operator, ?: is left associative. So this:

  $arg = 'T';
  $vehicle = ( ( $arg == 'B' ) ? 'bus' :
              ( $arg == 'A' ) ? 'airplane' :
              ( $arg == 'T' ) ? 'train' :
              ( $arg == 'C' ) ? 'car' :
              ( $arg == 'H' ) ? 'horse' :
              'feet' );
  echo $vehicle;
prints horse.


Some bitching about functions:

Quote (veekun)

Function calls are apparently rather expensive.
Some built-in functions interact with reference-returning functions in, er, a strange way.
As mentioned elsewhere, a lot of things that look like functions or look like they should be functions are actually language constructs, so nothing that works with functions will work with them.
Function arguments can have “type hints”, which are basically just static typing. But you can’t require that an argument be an int or string or object or other “core” type, even though every builtin function uses this kind of typing, probably because int is not a thing in PHP. (See above about (int).) You also can’t use the special pseudo-type decorations used heavily by builtin functions: mixed, number, or callback. (callable is allowed as of PHP 5.4.)

As a result, this:

  function foo(string $s) {}

  foo("hello world");
produces the error:

  PHP Catchable fatal error:  Argument 1 passed to foo() must be an instance of string, string given, called in...
You may notice that the “type hint” given doesn’t actually have to exist; there is no string class in this program. If you try to use ReflectionParameter::getClass() to examine the type hint dynamically, then it will balk that the class doesn’t exist, making it impossible to actually retrieve the class name.
A function’s return value can’t be hinted.


Seriously. Read the whole article. It's painful. Just because you can get things done with PHP doesn't mean that you should use it. Cutting down on development time and testing time is how real software engineers get things done.

This post was edited by rockonkenshin on Mar 3 2014 07:27am
Go Back To Programming & Development Topic List
Prev1323334353656Next
Add Reply New Topic New Poll