Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Design Patterns
Index -> General Programming
Goto page 1, 2, 3  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Martin




PostPosted: Sun Mar 06, 2005 8:49 pm   Post subject: Design Patterns

An interesting read on writing better code.

Design patterns are recurring solutions to software design problems you find again and again in real-world application development. Design patterns are about design and interaction of objects, as well as providing a communication platform concerning elegant, reusable solutions to commonly encountered programming challenges.

http://www.dofactory.com/Patterns/Patterns.aspx

The sample code is in C#. It should be fairly easy to read and translate over to other languages though.
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Sun Mar 06, 2005 10:53 pm   Post subject: (No subject)

Honestly, I looked at these, and most of them are only really useful if you're using a completely brain-dead language like C# or Java. Sometimes you can't avoid that, but I just want to put this into perspective.
rizzix




PostPosted: Sun Mar 06, 2005 11:23 pm   Post subject: (No subject)

wtd: whats with the unnecessary adjectives? Laughing

so anyways the stuff listed up there are really just conventions. the most important of the lot include: Factories, Iterators, Observers and Delegation (dunno but did they include that there? *shurgs*). The rest are unnecessary stuff IMHO.
wtd




PostPosted: Mon Mar 07, 2005 4:33 am   Post subject: (No subject)

rizzix wrote:
wtd: whats with the unnecessary adjectives? Laughing


If you're counting "completely brain-dead" as unnecessary adjectives, then in the case of the languages named (and a good many others), they're quite necessary. Aside from their large libraries, and the backing of large corporations which have used their influence to quash alternatives (or at least relegate alternatives to academic curiosities), such languages have no redeeming qualities.

Now, that said, that corporate support sometimes makes them useful. However, useful does not by any means necessarily mean good, and any computer scientist should know the difference.
Martin




PostPosted: Mon Mar 07, 2005 8:54 am   Post subject: (No subject)

One of the uses of design patters is that (apparently) they help to write platform independant code.

I have a course on them in my 2A semester (Jan - Apr 2006).
rizzix




PostPosted: Mon Mar 07, 2005 3:06 pm   Post subject: (No subject)

wtd wrote:
rizzix wrote:
wtd: whats with the unnecessary adjectives? Laughing


If you're counting "completely brain-dead" as unnecessary adjectives, then in the case of the languages named (and a good many others), they're quite necessary. Aside from their large libraries, and the backing of large corporations which have used their influence to quash alternatives (or at least relegate alternatives to academic curiosities), such languages have no redeeming qualities.
welll. thats your opinion...
wtd




PostPosted: Mon Mar 07, 2005 3:27 pm   Post subject: (No subject)

Name a single good thing either language contains which is not merely intended to compensate for some other basic deficiency.
Martin




PostPosted: Mon Mar 07, 2005 4:04 pm   Post subject: (No subject)

C# is backed by the most profitable company ever.

Wait a second...
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Mon Mar 07, 2005 4:24 pm   Post subject: (No subject)

University of Waterloo was paid $12mil to start teaching C#.

Wait a second...
wtd




PostPosted: Mon Mar 07, 2005 5:35 pm   Post subject: (No subject)

Heh. I already mentioned backing by large corporations. Smile

And if we're going to count that, Java's on a pretty solid footing. IBM, Sun, HP, etc. all throwing their weight behind it.
Hikaru79




PostPosted: Mon Mar 07, 2005 8:28 pm   Post subject: (No subject)

If we're going to go with that method of argument, name some things that these languages LACK that others don't Wink
wtd




PostPosted: Mon Mar 07, 2005 9:17 pm   Post subject: (No subject)

  • Decent support for generics. Not only based on type. Consider templates in C++ or generics in Ada. A simple example: a lottery ticket.

    code:
    template <size_t N>
    class LotteryTicket
    {
       private:
          int numbers[N];
       public:
          LotteryTicket();
          int operator[](size_t index) const;
          bool operator==(const LotteryTicket<N>& other_ticket) const;
          int matching_numbers(const LotteryTicket<N>& other_ticket) const;
    };


    code:
    generic
       N : Positive;
    package Lottery_Ticket is
       subtype Index_Type is Positive range 1..N;
       type Ticket is limited private;
       
       procedure Make(T : out Ticket);
       function "()" (T : in Ticket; Index : in Index_Type) return Integer;
       function "=" (T1, T2 : in Ticket) return Boolean;
       function Matching_Numbers(T1, T2 : in Ticket) return Natural;
    private
       type Ticket is array (1..N) of Integer;
    end Lottery_Ticket;

  • The ability to deal with functions as first class entities. Let's say I have a Name class with first and last name properties.

    code:
    using System;

    class Name
    {
       private string first, last;

       public this(string f, string l)
       {
          first = f;
          last = l;
       }

       public string First
       {
          get { return first; }
       }

       public string Last
       {
          get { return last; }
       }
    }


    Now, how do I sort based on last name? Why shouldn't it be as simple as:

    code:
    class Name
       attr_reader :first, :last

       def initialize(first, last)
          @first, @last = first, last
       end
    end

    names = [Name.new("Bob", "Smith"), Name.new("John", "Doe")]
    sorted_names = names.sort { |a, b| a.last <=> b.last }


    Or:

    code:
    data Name = Name {first::String, last::String}

    names = [Name "Bob" "Smith", Name "John" "Doe"]
    sortedNames = sortBy (\a b -> last a `compare` last b) names

  • Why should it be difficult to construct lists? Neither Java nor C# offer sane syntax for expediting the creation of many useful data structures (lists, vectors, hashtables).
  • No standalone functions. Heck, Java and C# even acknowledge the need for such by including static members and member functions. Yet, somehow these got left out.
  • Multiple inheritance. MI can greatly reduce the need for standalone functions and data, but it's missing too. Consider the case of Eiffel vs. Java, for instance. In Java you use System.out, which is static member of the System class. In Eiffel, all classes inherit std_output, so they can use such things without having to go into a different class.


Let's see the reaction to those before I go on. Smile
rizzix




PostPosted: Mon Mar 07, 2005 9:58 pm   Post subject: (No subject)

Ha! Its all missleading. You see you've just pointed out mostly to syntax sugar that Java and C# dont have. The idea behind Java and C#, is to include the bare minimum in the language and knock out the additional stuff into libraries. This i believe is a plus point on behalf of Java and C#, most other languages are simply bloated, but these two languages have rich and diverse libraries.

- templates
well ur temaplate design is bad. its is not a good idea to pass values as arguments to templates since you'll almost never come across the "need" to do so (unnecessary syntax sugar leads to a TIMTOWTDI effect, which is bad as far as full-fledge programming languages are concerned. scripting languages are an exception). As for types, java has generics, and java does it far better than c++, taking care of the potential flaws with the c++ template design. The only downfall (due to generics in java) is the fact that learning java just got a little harder, with the added complexity. (but java was never intended to be the easiest language to learn)

- functions as first class entities
As i said syntax sugar. It does reduce code but is not required. In java the same thing can be accomplished likewise:
code:
public class Name {
   private String first, last;

   public Name(String f, String l)
   {
      first = f;
      last = l;
   }

   public String getFirst {return first;}
   public String getLast {return last;}
}
code:
import java.util.*; ...

Name[] names = {new Name("Bob", "Smith"), new Name("John", "Doe")};

Arrays.sort(names,
    new Comparator() {
        public int compare(Name n1, Name n2) {
            return n1.getLast().compareTo(n2.getLast());
        }
    }
);


- Construction of lists
It would be a good idea to have syntax sugar for hashtables at the least, in Java or C#. But its difficult to change that now.

- No standalone functions
That would go against the consistancy and idealogy of both these languages. These languages depict object interactions, with only one class of the many, being the application class (has the "main" method). I dont see this as a drawback but rather as a plus point. The language is not bloated with features and syntax sugar.

- Multiple inheritance
What happens when two classes define the same symbols? But it is a fact that Single Inheritance has lead to less complexity in object design and modelling (specially in 1000000 lins of code projects) thus further supports extensibility and maintainance once again specially in large projects (hence the awesome support by huge firms). The only drawback is that designing is more difficult as compared to MI design. If ur not a big fan of design before code, then you might as well stay away from these langauges.
Hikaru79




PostPosted: Mon Mar 07, 2005 10:02 pm   Post subject: (No subject)

Razz Wow. WTD never disappoints! ^__^

I just have a few questions. I'm only just starting C++ so I don't understand what you mean by "templates" but just by looking at it, it looks an awful lot like an interface or abstract class in java. I'm guessing there's a vital difference there... what is it?

Also, Java *does* have Vectors and the other stuff you mention... or did you just mean you don't like the way that they're implemented?
rizzix




PostPosted: Mon Mar 07, 2005 10:09 pm   Post subject: (No subject)

wait sorry, my gernerics counter might not have properly countered ur argument: i dont know ada.
Display posts from previous:   
   Index -> General Programming
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 3  [ 38 Posts ]
Goto page 1, 2, 3  Next
Jump to:   


Style:  
Search: