Click here to Skip to main content
15,890,897 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Do you Program in Paragraphs or Sentances? Pin
KBZX50001-Jun-18 4:37
KBZX50001-Jun-18 4:37 
GeneralRe: Do you Program in Paragraphs or Sentances? Pin
kalberts1-Jun-18 8:07
kalberts1-Jun-18 8:07 
GeneralRe: Do you Program in Paragraphs or Sentances? Pin
kalberts1-Jun-18 2:42
kalberts1-Jun-18 2:42 
GeneralRe: Do you Program in Paragraphs or Sentences? Pin
Bruce Patin1-Jun-18 4:11
Bruce Patin1-Jun-18 4:11 
GeneralRe: Do you Program in Paragraphs or Sentences? Pin
RandyBuchholz1-Jun-18 4:14
RandyBuchholz1-Jun-18 4:14 
GeneralRe: Do you Program in Paragraphs or Sentences? Pin
Bruce Patin1-Jun-18 4:43
Bruce Patin1-Jun-18 4:43 
GeneralRe: Do you Program in Paragraphs or Sentences? Pin
MSBassSinger1-Jun-18 4:39
professionalMSBassSinger1-Jun-18 4:39 
GeneralRe: Do you Program in Paragraphs or Sentences? Pin
RandyBuchholz1-Jun-18 6:18
RandyBuchholz1-Jun-18 6:18 
When I started I was actually thinking more about separating concepts and mechanics, or maybe better, business vs technology. But I think I lost that some when playing with creating my examples. )

In business applications (vs scientific/engineering) most methods implement some part of a business function.

At an absurdum extreme you could write the application in one procedural block with thousands of lines of branching/conditional code, where each line does no more than a single thing. It contains an atomic concept. So, you wouldn't write if(x == 1 || x == 3), that is two concepts. At this extreme, every atomic thought is crystal clear, but the big-picture of what the method does becomes a forest-trees thing.

We decompose software into logical, understandably named chunks, like methods and classes. At another absurd extreme, we could make each concept a method - bool IsValueEqualToOne(int x) {if x ==1 return true else return false}. This is just as bad. We have only translated from a technical representation (x == 1)? to a business representation IsValueEqualToOne.

In real-world programming we balance the size and form of our chunks. In some cases, it is better to combine at a "technical" level - `if(x == 1 || x == 3)`. In others, a business level is better
// transfer
if(AccountHasFunds(sourceAccount, amount)){
  debit(sourceAccount, amount);
  credit(targetAccount amount);
}

At the opposite extreme or "can't see the forest for the trees" is "needle in a haystack", one liners. Like the examples I gave. ( and tried to disclaim as how I would actually do it. Smile | :) )

So, to your question
Quote:
compiler does something more optimized... Or perhaps some other underlying reason?

In rereading it sounds like I may be advocating "one-liners", but not really. All the LINQ and stuff has a greater chance of compiler confusion than optimization. Maybe the best I can think of is that each method we write contains a business purpose and a technical implementation. The clearest code communicates both, and the best code does this in a maintainable way.
With LINQ style and functional becoming popular I was curious to see if people were writing more that way.

My preferred method of coding combines approaches, made easier with local functions. (I just make up "transaction syntax for simplicity)
void TransferFunds(source, target, amount){

  // Business - more compressed to highlight business logic
  if(AccountHasFunds(sourceAccount, amount)){
    transaction {
      debit(sourceAccount, amount);
      credit(targetAccount amount);
    }
    success: {}
    rollback: {}
  } else { CancelTransfer(); }

  // Technology - more expanded too see details and maintain

  [Description("Validates account balance equals or exceeds amount")]
  bool AccountHasFunds(string account, decimal amount){
    var accountBalance = account.GetBalance();
    if ( accountBalance >= amount){
      return true;
    else {
      return false;
    }
  }

  [Description("Debits amount from account")]
  void Credit(…){
    …
  }

  ...
}

GeneralRe: Do you Program in Paragraphs or Sentences? Pin
kalberts1-Jun-18 8:39
kalberts1-Jun-18 8:39 
GeneralRe: Do you Program in Paragraphs or Sentences? Pin
Kirk 103898211-Jun-18 5:14
Kirk 103898211-Jun-18 5:14 
GeneralRe: Do you Program in Paragraphs or Sentences? Pin
Gerry Schmitz1-Jun-18 6:03
mveGerry Schmitz1-Jun-18 6:03 
GeneralRe: Do you Program in Paragraphs or Sentences? Pin
RandyBuchholz1-Jun-18 6:27
RandyBuchholz1-Jun-18 6:27 
GeneralRe: Do you Program in Paragraphs or Sentences? Pin
Gerry Schmitz1-Jun-18 6:38
mveGerry Schmitz1-Jun-18 6:38 
GeneralRe: Do you Program in Paragraphs or Sentences? Pin
RandyBuchholz1-Jun-18 7:08
RandyBuchholz1-Jun-18 7:08 
GeneralRe: Do you Program in Paragraphs or Sentences? Pin
Gerry Schmitz1-Jun-18 7:44
mveGerry Schmitz1-Jun-18 7:44 
GeneralRe: Do you Program in Paragraphs or Sentences? Pin
kalberts1-Jun-18 8:52
kalberts1-Jun-18 8:52 
GeneralRe: Do you Program in Paragraphs or Sentences? Pin
Vivi Chellappa2-Jun-18 4:21
professionalVivi Chellappa2-Jun-18 4:21 
GeneralThought of the Day Pin
OriginalGriff31-May-18 4:56
mveOriginalGriff31-May-18 4:56 
GeneralRe: Thought of the Day Pin
lopatir31-May-18 5:00
lopatir31-May-18 5:00 
GeneralRe: Thought of the Day Pin
OriginalGriff31-May-18 5:07
mveOriginalGriff31-May-18 5:07 
GeneralRe: Thought of the Day Pin
Johnny J.31-May-18 5:23
professionalJohnny J.31-May-18 5:23 
GeneralRe: Thought of the Day Pin
Richard Deeming31-May-18 5:31
mveRichard Deeming31-May-18 5:31 
GeneralRe: Thought of the Day Pin
jeron131-May-18 6:05
jeron131-May-18 6:05 
GeneralRe: Thought of the Day Pin
Eric Lynch31-May-18 7:26
Eric Lynch31-May-18 7:26 
GeneralRe: Thought of the Day Pin
Mike Hankey31-May-18 7:26
mveMike Hankey31-May-18 7:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.