language-construct

How can I use C# style enumerations in Ruby?

I just want to know the best way to emulate a C# style enumeration in Ruby. ...

C++ constructs replacing C constructs

After discussing with a newly arrived developer in my team, I realized that there are still, in C++, habits of using C constructs because they are supposed to be better (i.e. faster, leaner, prettier, pick your reason). What are the examples worth sharing, showing a C constructs, compared to the similar C++ construct? For each example,...

On your very first program, which construct hooked you on programming?

To me it was the If statement, I'm psyched up, since then I believed that computers are very intelligent, or I can at least make it appear intelligent because of it. ...

What is the difference between a language construct and a "built-in" function in PHP?

Hi guys, I know that include, isset, require, print, echo, and some others are not functions but language constructs. Some of these language constructs need parentheses, others don't. require 'file.php'; isset($x); Some have a return value, others do not. print 'foo'; //1 echo 'foo'; //no return value So what is the internal dif...

Is there a programming language that allows variable declaration at call site?

Update 2: examples removed, because they were misleading. The ones below are more relevant. My question: Is there a programming language with such a construct? Update: Now when I think about it, Prolog has something similar. I even allows defining operations at definition line. (forget about backtracking and relations - think about ...

Does it exists a shorter if statement in PHP?

Is it possible to rewrite this to be shorter somehow? if (isset($_POST['pic_action'])){ $pic_action=$_POST['pic_action']; } else { $pic_action=0; } I have seen it somewhere but forgot... :/ BTW, please explain your code also if you like! Thanks ...

if statement on one line if poss...

I am printing an image using an ID which is generated. however i wanted to do a check to see if this image exists and if it doesnt print no-image.jpg instead... <img src="phpThumb/phpThumb.php?src=../public/images/'.$row["id"].'/th.jpg&w=162" alt="" width="162" /> It would be great if this could be kept on one line is possible. Any...

?: operator PHP

I saw this today in some PHP code. $items = $items ?: $this->_handle->result('next', $this->_result, $this); What is the ?: doing? Is it a Ternary operator without a return true value? A PHP 5.3 thing? I tried some test code but got syntax errors. ...

what does this syntax ( page = $page ? $page : 'default' ) in php mean?

i'm new to php. I came across this syntax in wordpress. Can anyone explain to me the last line of that code? $page = $_SERVER['REQUEST_URI']; $page = str_replace("/","",$page); $page = str_replace(".php","",$page); **$page = $page ? $page : 'default'** the last line(bolded). thanks ...

What is ?: in PHP 5.3?

Possible Duplicate: What is the PHP ? : operator called and what does it do? From http://twitto.org/ <?PHP require __DIR__.'/c.php'; if (!is_callable($c = @$_GET['c'] ?: function() { echo 'Woah!'; })) throw new Exception('Error'); $c(); ?> Twitto uses several new features available as of PHP 5.3: The DIR constant The ...

Python: Any way to declare constant parameters?

I have a method: def foo(bar): # ... Is there a way to mark bar as constant? Such as "The value in bar cannot change" or "The object pointed to by bar cannot change". ...

Should one avoid certain programming constructs (and others) for maintenance's sake?

I'm working on a non-personal project, so it's safe to say that the maintenance programmer will not be me, for otherwise I wouldn't need to ask this question. Now there are some constructs (delegates, lambda expressions) which I would like to try in my code, not to intentionally make the code harder to read, but because they lend themse...

In PHP, why wasn't echo implemented as a function? (not echo vs. printf)

I'm just curious. In PHP, why wasn't echo implemented as a function? Why didn't PHP just give us printf and never tell about echo? Please note that: This is not a question about echo vs. printf. I already knew that echo is a language construct. UPDATE: By the way, was printf implemented using echo? ...

Is there a language construct similar to PHPs list() in C#?

Hi, PHP has a language construct list() which provides multiple variables assignment in one statement. $a = 0; $b = 0; list($a, $b) = array(2, 3); // Now $a is equal to 2 and $b is equal to 3. Is there a similar thing in C#? If not, is there any workaround which may help to avoid code like the following, without having to deal with ...