Search Results

Search found 50973 results on 2039 pages for 'class names'.

Page 31/2039 | < Previous Page | 27 28 29 30 31 32 33 34 35 36 37 38  | Next Page >

  • Documenting class attribute

    - by Dewfy
    Following sample is taken from "Dive into python" book. class MP3FileInfo(FileInfo): "store ID3v1.0 MP3 tags" tagDataMap = ... This sample shows documenting the MP3FileInfo, but how can I add help to MP3FileInfo. tagDataMap

    Read the article

  • How to see .class content in Eclipse?

    - by mac
    Sometimes, in Eclipse , i press a combination of keys which take me to the editor page that shows contents of my .class file. I never seem to be able to remember what that key combination is. Can someone please let me know?

    Read the article

  • importing class and its function from another file [Python]

    - by user343934
    Hi everyone, I am having little bit problem in importing classes in python. My work flow goes like this -index.py ---class template: ------def header(): ------def body(): ------def footer(): -display.py I want to call function header(), body() and footer () in my display.py page. Will anyone make me clear about this issue in python. Thanks for your concern.

    Read the article

  • C# : having a "+" in the class name ?

    - by Graveen
    Hello, class name: MyAssembly.MyClass+MyOtherClass The problem is obviously the + as separator, instead of traditionnal dot, its function, and to find official documentation to see if others separators exist Thank you in advance !

    Read the article

  • ASP.NET MVC ‘Extendable-hooks’ – ControllerActionInvoker class

    - by nmarun
    There’s a class ControllerActionInvoker in ASP.NET MVC. This can be used as one of an hook-points to allow customization of your application. Watching Brad Wilsons’ Advanced MP3 from MVC Conf inspired me to write about this class. What MSDN says: “Represents a class that is responsible for invoking the action methods of a controller.” Well if MSDN says it, I think I can instill a fair amount of confidence into what the class does. But just to get to the details, I also looked into the source code for MVC. Seems like the base class Controller is where an IActionInvoker is initialized: 1: protected virtual IActionInvoker CreateActionInvoker() { 2: return new ControllerActionInvoker(); 3: } In the ControllerActionInvoker (the O-O-B behavior), there are different ‘versions’ of InvokeActionMethod() method that actually call the action method in question and return an instance of type ActionResult. 1: protected virtual ActionResult InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary<string, object> parameters) { 2: object returnValue = actionDescriptor.Execute(controllerContext, parameters); 3: ActionResult result = CreateActionResult(controllerContext, actionDescriptor, returnValue); 4: return result; 5: } I guess that’s enough on the ‘behind-the-screens’ of this class. Let’s see how we can use this class to hook-up extensions. Say I have a requirement that the user should be able to get different renderings of the same output, like html, xml, json, csv and so on. The user will type-in the output format in the url and should the get result accordingly. For example: http://site.com/RenderAs/ – renders the default way (the razor view) http://site.com/RenderAs/xml http://site.com/RenderAs/csv … and so on where RenderAs is my controller. There are many ways of doing this and I’m using a custom ControllerActionInvoker class (even though this might not be the best way to accomplish this). For this, my one and only route in the Global.asax.cs is: 1: routes.MapRoute("RenderAsRoute", "RenderAs/{outputType}", 2: new {controller = "RenderAs", action = "Index", outputType = ""}); Here the controller name is ‘RenderAsController’ and the action that’ll get called (always) is the Index action. The outputType parameter will map to the type of output requested by the user (xml, csv…). I intend to display a list of food items for this example. 1: public class Item 2: { 3: public int Id { get; set; } 4: public string Name { get; set; } 5: public Cuisine Cuisine { get; set; } 6: } 7:  8: public class Cuisine 9: { 10: public int CuisineId { get; set; } 11: public string Name { get; set; } 12: } Coming to my ‘RenderAsController’ class. I generate an IList<Item> to represent my model. 1: private static IList<Item> GetItems() 2: { 3: Cuisine cuisine = new Cuisine { CuisineId = 1, Name = "Italian" }; 4: Item item = new Item { Id = 1, Name = "Lasagna", Cuisine = cuisine }; 5: IList<Item> items = new List<Item> { item }; 6: item = new Item {Id = 2, Name = "Pasta", Cuisine = cuisine}; 7: items.Add(item); 8: //... 9: return items; 10: } My action method looks like 1: public IList<Item> Index(string outputType) 2: { 3: return GetItems(); 4: } There are two things that stand out in this action method. The first and the most obvious one being that the return type is not of type ActionResult (or one of its derivatives). Instead I’m passing the type of the model itself (IList<Item> in this case). We’ll convert this to some type of an ActionResult in our custom controller action invoker class later. The second thing (a little subtle) is that I’m not doing anything with the outputType value that is passed on to this action method. This value will be in the RouteData dictionary and we’ll use this in our custom invoker class as well. It’s time to hook up our invoker class. First, I’ll override the Initialize() method of my RenderAsController class. 1: protected override void Initialize(RequestContext requestContext) 2: { 3: base.Initialize(requestContext); 4: string outputType = string.Empty; 5:  6: // read the outputType from the RouteData dictionary 7: if (requestContext.RouteData.Values["outputType"] != null) 8: { 9: outputType = requestContext.RouteData.Values["outputType"].ToString(); 10: } 11:  12: // my custom invoker class 13: ActionInvoker = new ContentRendererActionInvoker(outputType); 14: } Coming to the main part of the discussion – the ContentRendererActionInvoker class: 1: public class ContentRendererActionInvoker : ControllerActionInvoker 2: { 3: private readonly string _outputType; 4:  5: public ContentRendererActionInvoker(string outputType) 6: { 7: _outputType = outputType.ToLower(); 8: } 9: //... 10: } So the outputType value that was read from the RouteData, which was passed in from the url, is being set here in  a private field. Moving to the crux of this article, I now override the CreateActionResult method. 1: protected override ActionResult CreateActionResult(ControllerContext controllerContext, ActionDescriptor actionDescriptor, object actionReturnValue) 2: { 3: if (actionReturnValue == null) 4: return new EmptyResult(); 5:  6: ActionResult result = actionReturnValue as ActionResult; 7: if (result != null) 8: return result; 9:  10: // This is where the magic happens 11: // Depending on the value in the _outputType field, 12: // return an appropriate ActionResult 13: switch (_outputType) 14: { 15: case "json": 16: { 17: JavaScriptSerializer serializer = new JavaScriptSerializer(); 18: string json = serializer.Serialize(actionReturnValue); 19: return new ContentResult { Content = json, ContentType = "application/json" }; 20: } 21: case "xml": 22: { 23: XmlSerializer serializer = new XmlSerializer(actionReturnValue.GetType()); 24: using (StringWriter writer = new StringWriter()) 25: { 26: serializer.Serialize(writer, actionReturnValue); 27: return new ContentResult { Content = writer.ToString(), ContentType = "text/xml" }; 28: } 29: } 30: case "csv": 31: controllerContext.HttpContext.Response.AddHeader("Content-Disposition", "attachment; filename=items.csv"); 32: return new ContentResult 33: { 34: Content = ToCsv(actionReturnValue as IList<Item>), 35: ContentType = "application/ms-excel" 36: }; 37: case "pdf": 38: string filePath = controllerContext.HttpContext.Server.MapPath("~/items.pdf"); 39: controllerContext.HttpContext.Response.AddHeader("content-disposition", 40: "attachment; filename=items.pdf"); 41: ToPdf(actionReturnValue as IList<Item>, filePath); 42: return new FileContentResult(StreamFile(filePath), "application/pdf"); 43:  44: default: 45: controllerContext.Controller.ViewData.Model = actionReturnValue; 46: return new ViewResult 47: { 48: TempData = controllerContext.Controller.TempData, 49: ViewData = controllerContext.Controller.ViewData 50: }; 51: } 52: } A big method there! The hook I was talking about kinda above actually is here. This is where different kinds / formats of output get returned based on the output type requested in the url. When the _outputType is not set (string.Empty as set in the Global.asax.cs file), the razor view gets rendered (lines 45-50). This is the default behavior in most MVC applications where-in a view (webform/razor) gets rendered on the browser. As you see here, this gets returned as a ViewResult. But then, for an outputType of json/xml/csv, a ContentResult gets returned, while for pdf, a FileContentResult is returned. Here are how the different kinds of output look like: This is how we can leverage this feature of ASP.NET MVC to developer a better application. I’ve used the iTextSharp library to convert to a pdf format. Mike gives quite a bit of detail regarding this library here. You can download the sample code here. (You’ll get an option to download once you open the link). Verdict: Hot chocolate: $3; Reebok shoes: $50; Your first car: $3000; Being able to extend a web application: Priceless.

    Read the article

  • How to avoid general names for abstract classes?

    - by djechlin
    In general it's good to avoid words like "handle" or "process" as part of routine names and class names, unless you are dealing with (e.g.) file handles or (e.g.) unix processes. However abstract classes often don't really know what they're going to do with something besides, say, process it. In my current situation I have an "EmailProcessor" that logs into a user's inbox and processes messages from it. It's not really clear to me how to give this a more precise name, although I've noticed the following style matter arises: better to treat derived classes as clients and named the base class by the part of the functionality it implements? Gives it more meaning but will violate is-a. E.g. EmailAcquirer would be a reasonable name since it's acquiring for the derived class, but the derived class won't be acquiring for anyone. Or just really vague name since who knows what the derived classes will do. However "Processor" is still too general since it's doing many relevant operations, like logging in and using IMAP. Any way out of this dilemma? Problem is more evident for abstract methods, in which you can't really answer the question "what does this do?" because the answer is simply "whatever the client wants."

    Read the article

  • Class hierarchy problem in this social network model

    - by Gerenuk
    I'm trying to design a class system for a social network data model - basically a link/object system. Now I have roughly the following structure (simplified and only relevant methods shown) class Data: "used to handle the data with mongodb" "can link, unlink data and also return other linked data" "is basically a proxy object that only stores _id and accesses mongodb on requests" "it looks like {_id: ..., _out: [id1, id2,...], _inc: [id3, id4, ...]}" def get_node(self, id) "create a new Data object from the underlying mongodb" "each data object can potentially create a reference object to new mongo data" "this is needed when the data returns the linked objects" class Node: """ this class proxies linking calls to .data it includes additional network logic operations whereas Data only contains a basic database solution """ def __init__(self, data): "the infrastructure realization is stored as composition by an included object data" "Node bascially proxies most calls to the infrastructure object data" def get_node(self, data): "creates a new object of class Object or Link depending on data" class Object(Node): "can have multiple connections to Link" class Link(Node): "has one 'in' and one 'out' connection to an Object" This system is working, however maybe wouldn't work outside Python. Note that after reading links Now I have two questions here: 1) I want to infrastructure of the data storage to be replacable. Earlier I had Data as a superclass of Node so that it provided the neccessary calls. But (without dirty Python tricks) you cannot replace the superclass dynamically. Is using composition therefore recommended? The drawback is that I have to proxy most calls (link, unlink etc). Any thoughts? 2) The class Node contains the common method .get_node which is used to built new Object or Link instances after reading out the data. Some attribute of data decided whether the object which is only stored by id should be instantiated as an Object or Link class. The problem here is that Node needs to know about Object and Link in advance, which seems dodgy. Do you see a different solution? Both Object and Link need to instantiate one of all possible types depending on what the find in their linked data. Are there any other ideas how to implement a flexible Object/Link structure where the underlying database storage is isolated?

    Read the article

  • problem with PHP class function ()

    - by lusey
    hello this is my first question here and i hope you can help me .. I am trying to find a soloution of the towers of hanoi problem by three search ways (BFS-DFS-IDS) so I use "state" class whitch defined by 5 variables as here : class state { var $tower1 = array(); var $tower2 = array(); var $tower3 = array(); var $depth; var $neighbors = array(); and it also has many function one of them is getneighbors() which supposed to fill the array $neighbors with state neighbors and they are from the type "state" and here is the function : function getneighbors () { $temp=$this->copy(); $neighbor1= $this->copy(); $neighbor2= $this->copy(); $neighbor3= $this->copy(); $neighbor4= $this->copy(); $neighbor5= $this->copy(); $neighbor6= $this->copy(); if(!Empty($temp->tower1)) { if(!Empty($neighbor1->tower2)) { if(end($neighbor1->tower1) < end($neighbor1->tower2)) { array_unshift($neighbor1->tower2,array_pop($neighbor1->tower1)); array_push($neighbors,$neighbor1); }} else { array_unshift($neighbor1->tower2, array_pop($neighbor1->tower1)); array_push($neighbors,$neighbor1); } if(!Empty($neighbor2->tower3)) { if(end($neighbor2->tower1) < end($neighbor2->tower3)) { array_unshift($neighbor2->tower3, array_pop($neighbor2->tower1)); array_push($neighbors,$neighbor2); }} else { array_unshift($neighbor2->tower3,array_shift($neighbor2->tower1)); array_push($neighbors,$neighbor2); } } if(!Empty($temp->tower2)) { if(!Empty($neighbor3->tower1)) { if(end($neighbor3->tower2) < end($neighbor3->tower1)) { array_unshift($neighbor3->tower1,array_shift($neighbor3->tower2)); array_push($neighbors,$neighbor3); } } else { array_unshift($neighbor3->tower1,array_shift($neighbor3->tower2)); array_push($neighbors,$neighbor3); } if(!Empty($neighbor4->tower3)) { if(end($neighbor4->tower2) < end($neighbor4->tower3)) { array_unshift($neighbor4->tower1,array_shift($neighbor4->tower2)); array_push($neighbors,$neighbor4); } } else{ array_unshift($neighbor4->tower3,array_shift($neighbor4->tower2)); array_push($neighbors,$neighbor4); } } if(!Empty($temp->tower3)) { if(!Empty($neighbor5->tower1)) { if(end($neighbor5->tower3) < end($neighbor5->tower1)) {array_unshift($neighbor5->tower1,array_shift($neighbor5->tower3)); array_push($neighbors,$neighbor5); } } else{ array_unshift($neighbor5->tower1,array_shift($neighbor5->tower3)); array_push($neighbors,$neighbor5);} if(!Empty($neighbor6->tower2)) { if(end($neighbor6->tower3) < end($neighbor6->tower2)) { array_unshift($neighbor6->tower2,array_shift($neighbor6->tower3)); array_push($neighbors,$neighbor6); }} else{ array_unshift($neighbor6->tower2,array_shift($neighbor6->tower3)); array_push($neighbors,$neighbor6);} } return $neighbors; } note that toString and equals and copy are defined too now the problem is that when I call getneighbors() it returns an empty $neighbors array can you pleas tell me the problem ?

    Read the article

  • Mutable class as a child of an immutable class

    - by deamon
    I want to have immutable Java objects like this (strongly simplyfied): class Immutable { protected String name; public Immutable(String name) { this.name = name; } public String getName() { return name; } } In some cases the object should not only be readable but mutable, so I could add mutability through inheritance: public class Mutable extends Immutable { public Mutable(String name) { super(name); } public void setName(String name) { super.name = name; } } While this is technically fine, I wonder if it conforms with OOP and inheritance that mutable is also of type immutable. I want to avoid the OOP crime to throw UnsupportedOperationException for immutable object, like the Java collections API does. What do you think? Any other ideas?

    Read the article

  • Should this immutable struct be a mutable class?

    - by ChaosPandion
    I showed this struct to a fellow programmer and they felt that it should be a mutable class. They felt it is inconvenient not to have null references and the ability to alter the object as required. I would really like to know if there are any other reasons to make this a mutable class. [Serializable] public struct PhoneNumber : ICloneable, IEquatable<PhoneNumber> { private const int AreaCodeShift = 54; private const int CentralOfficeCodeShift = 44; private const int SubscriberNumberShift = 30; private const int CentralOfficeCodeMask = 0x000003FF; private const int SubscriberNumberMask = 0x00003FFF; private const int ExtensionMask = 0x3FFFFFFF; private readonly ulong value; public int AreaCode { get { return UnmaskAreaCode(value); } } public int CentralOfficeCode { get { return UnmaskCentralOfficeCode(value); } } public int SubscriberNumber { get { return UnmaskSubscriberNumber(value); } } public int Extension { get { return UnmaskExtension(value); } } public PhoneNumber(ulong value) : this(UnmaskAreaCode(value), UnmaskCentralOfficeCode(value), UnmaskSubscriberNumber(value), UnmaskExtension(value), true) { } public PhoneNumber(int areaCode, int centralOfficeCode, int subscriberNumber) : this(areaCode, centralOfficeCode, subscriberNumber, 0, true) { } public PhoneNumber(int areaCode, int centralOfficeCode, int subscriberNumber, int extension) : this(areaCode, centralOfficeCode, subscriberNumber, extension, true) { } private PhoneNumber(int areaCode, int centralOfficeCode, int subscriberNumber, int extension, bool throwException) { value = 0; if (areaCode < 200 || areaCode > 989) { if (!throwException) return; throw new ArgumentOutOfRangeException("areaCode", areaCode, @"The area code portion must fall between 200 and 989."); } else if (centralOfficeCode < 200 || centralOfficeCode > 999) { if (!throwException) return; throw new ArgumentOutOfRangeException("centralOfficeCode", centralOfficeCode, @"The central office code portion must fall between 200 and 999."); } else if (subscriberNumber < 0 || subscriberNumber > 9999) { if (!throwException) return; throw new ArgumentOutOfRangeException("subscriberNumber", subscriberNumber, @"The subscriber number portion must fall between 0 and 9999."); } else if (extension < 0 || extension > 1073741824) { if (!throwException) return; throw new ArgumentOutOfRangeException("extension", extension, @"The extension portion must fall between 0 and 1073741824."); } else if (areaCode.ToString()[1] - 48 > 8) { if (!throwException) return; throw new ArgumentOutOfRangeException("areaCode", areaCode, @"The second digit of the area code cannot be greater than 8."); } else { value |= ((ulong)(uint)areaCode << AreaCodeShift); value |= ((ulong)(uint)centralOfficeCode << CentralOfficeCodeShift); value |= ((ulong)(uint)subscriberNumber << SubscriberNumberShift); value |= ((ulong)(uint)extension); } } public object Clone() { return this; } public override bool Equals(object obj) { return obj != null && obj.GetType() == typeof(PhoneNumber) && Equals((PhoneNumber)obj); } public bool Equals(PhoneNumber other) { return this.value == other.value; } public override int GetHashCode() { return value.GetHashCode(); } public override string ToString() { return ToString(PhoneNumberFormat.Separated); } public string ToString(PhoneNumberFormat format) { switch (format) { case PhoneNumberFormat.Plain: return string.Format(@"{0:D3}{1:D3}{2:D4} {3:#}", AreaCode, CentralOfficeCode, SubscriberNumber, Extension).Trim(); case PhoneNumberFormat.Separated: return string.Format(@"{0:D3}-{1:D3}-{2:D4} {3:#}", AreaCode, CentralOfficeCode, SubscriberNumber, Extension).Trim(); default: throw new ArgumentOutOfRangeException("format"); } } public ulong ToUInt64() { return value; } public static PhoneNumber Parse(string value) { var result = default(PhoneNumber); if (!TryParse(value, out result)) { throw new FormatException(string.Format(@"The string ""{0}"" could not be parsed as a phone number.", value)); } return result; } public static bool TryParse(string value, out PhoneNumber result) { result = default(PhoneNumber); if (string.IsNullOrEmpty(value)) { return false; } var index = 0; var numericPieces = new char[value.Length]; foreach (var c in value) { if (char.IsNumber(c)) { numericPieces[index++] = c; } } if (index < 9) { return false; } var numericString = new string(numericPieces); var areaCode = int.Parse(numericString.Substring(0, 3)); var centralOfficeCode = int.Parse(numericString.Substring(3, 3)); var subscriberNumber = int.Parse(numericString.Substring(6, 4)); var extension = 0; if (numericString.Length > 10) { extension = int.Parse(numericString.Substring(10)); } result = new PhoneNumber( areaCode, centralOfficeCode, subscriberNumber, extension, false ); return result.value == 0; } public static bool operator ==(PhoneNumber left, PhoneNumber right) { return left.Equals(right); } public static bool operator !=(PhoneNumber left, PhoneNumber right) { return !left.Equals(right); } private static int UnmaskAreaCode(ulong value) { return (int)(value >> AreaCodeShift); } private static int UnmaskCentralOfficeCode(ulong value) { return (int)((value >> CentralOfficeCodeShift) & CentralOfficeCodeMask); } private static int UnmaskSubscriberNumber(ulong value) { return (int)((value >> SubscriberNumberShift) & SubscriberNumberMask); } private static int UnmaskExtension(ulong value) { return (int)(value & ExtensionMask); } } public enum PhoneNumberFormat { Plain, Separated }

    Read the article

  • UiElement from abstract class

    - by plotnick
    I placed a control into a grid. let's say the control is derived from public class 'ButBase' which is derived in its turn from System.Windows.Controls.Button. The code normally compiles and app works just fine. But there's something really annoying. When you try to switch to xaml-design tab it will say 'The document root element is not supported by the visual designer', which is normal and I'm totally okay with that, but the thing is, that all the xaml code is underlined and VS2010 says: 'Cannot create an instance of ButBase' although still normally compiles and able to run. I've tried the same code in VS2008, it said that needs to see a public parameterless constructor in the ButBase, and even after I put one it showed the same error. What do I miss here?

    Read the article

  • UiElement based on another class

    - by plotnick
    I placed a control into a grid. let's say the control is derived from public class 'ButBase' which is derived in its turn from System.Windows.Controls.Button. The code normally compiles and app works just fine. But there's something really annoying. When you try to switch to xaml-design tab it will say 'The document root element is not supported by the visual designer', which is normal and I'm totally okay with that, but the thing is, that all the xaml code is underlined and VS2010 says: 'Cannot create an instance of ButBase' although still normally compiles and able to run. I've tried the same code in VS2008, it said that needs to see a public parameterless constructor in the ButBase, and even after I put one it showed the same error. What do I miss here?

    Read the article

  • Flash AS3 undefined property MouseEvent in document class

    - by Lee
    Hi guys, this is my first time trying to use document classes in AS3 and im struggling. I am trying to add event listeners to a 2 levels deep movie clip, waiting for a click however i am getting the following error. ERROR: Access of undefined property MouseEvent package { import flash.display.MovieClip; import flash.media.Sound; import flash.media.SoundChannel; public class game extends MovieClip { public var snd_state = true; public function game() { ui_setup(); } public function ui_setup() { ui_mc.toggleMute_mc.addEventListener(MouseEvent.CLICK, snd_toggle); } public function snd_toggle(MouseEvent) { // 0 = No Sound, 1 = Full Sound trace("Toggle"); } } }

    Read the article

  • objective-c Derived class may not respond to base class method

    - by zadam
    Hi, I have derived from a 3rd party class, and when I attempt to call a method in the base class, I get the x may not respond to y compiler warning. How can I remove the warning? Repro: @interface ThirdPartyBaseClass : NSObject {} +(id)build; -(void)doStuff; @end @implementation ThirdPartyBaseClass +(id) build{ return [[[self alloc] init] autorelease]; } -(void)doStuff{ } @end @interface MyDerivedClass : ThirdPartyBaseClass {} +(id)buildMySelf; @end @implementation MyDerivedClass +(id)buildMySelf{ self = [ThirdPartyBaseClass build]; [self doStuff]; // compiler warning here - 'MyDerivedClass' may not respond to '+doStuff' return self; } @end Thanks!

    Read the article

  • How do I access variables with hyphenated names in Smarty?

    - by abeger
    I've got a PHP page that parses an XML file with SimpleXml, then passes that object to a Smarty template. My problem is that the XML file has hyphens in its tag names, e.g. video-player. In PHP, this is no problem, I just use $xml->{'video-player'} and everything's fine. Smarty, on the other hand, throws a fit when I try to use that syntax. The only solution I've come up with so far is to use a variable to store the name, e.g., { assign var=name value="video-player" } { $xml->$name } But this isn't terribly graceful to say the least. Is there another, better, approach to referring to a hyphenated variable name in Smarty?

    Read the article

  • UML Class Relationships

    - by 01010011
    Hi, I would like to confirm whether I am on the right track when identifying common UML class relationships. For example, is the relationship between: 1 a stackoverflow member and his/her stackoverflow user account categorized as a composition relationship or an aggregation relationship? At first I thought it was an association because this member "has a" account. However on second thought, I am thinking its composition because each "part" (user account) belongs to only one whole (user) at a time, meaning for as long as I am logged into stackoverflow, I have to use this one and only account until I log off. If I log back onto stackoverflow with a different account then its composition again. Do you agree? 2 a database and a person's user account an aggregation relationship? I think so because 1 database (the whole) can store 0...* number of user accounts (the parts) but another database can store the same user accounts. Finally, can anyone recommend a website that specializes in designing code using UML? Thanks in advance

    Read the article

  • Scala wont pattern match with java.lang.String and Case Class

    - by Stefan
    Hello fellow Scala Programmers I have been working with Scala for some month now, however I have a problem with some properly basic stuff, I am hoping you will help my out with it. case class PersonClass(name: String, age: Int) object CaseTester { def main(args:Array[String]) { val string = "hej" string match { case e:String => println(string) case PersonClass => println(string) } } } When I am doing like this I get error: pattern type is incompatible with expected type; found : object PersonClass required: java.lang.String case PersonClass = println(string) And if I then change the second line in the pattern matching to the following: case e:PersonClass => println(string) I then get the error: error: scrutinee is incompatible with pattern type; found : PersonClass required: java.lang.String case e:PersonClass = println(string) However if I change the string definition to the following it compiles fine in both cases. val string:AnyRef = "hej"

    Read the article

  • Accessing Class Variables from a List in a nice way in Python

    - by Dennis
    Suppose I have a list X = [a, b, c] where a, b, c are instances of the same class C. Now, all these instances a,b,c, have a variable called v, a.v, b.v, c.v ... I simply want a list Y = [a.v, b.v, c.v] Is there a nice command to do this? The best way I can think of is: Y = [] for i in X Y.append(i.v) But it doesn't seem very elegant ~ since this needs to be repeated for any given "v" Any suggestions? I couldn't figure out a way to use "map" to do this.

    Read the article

  • Why is prefixing column names considered bad practice?

    - by P.Brian.Mackey
    According to a popular SO post is it considered a bad practice to prefix table names. At my company every column is prefixed by a table name. This is difficult for me to read. I'm not sure the reason, but this naming is actually the company standard. I can't stand the naming convention, but I have no documentation to back up my reasoning. All I know is that reading AdventureWorks is much simpler. In this our company DB you will see a table, Person and it might have column name: Person_First_Name or maybe even Person_Person_First_Name (don't ask me why you see person 2x) Why is it considered a bad practice to pre-fix column names? Are underscores considered evil in SQL as well? Note: I own Pro SQL Server 2008 - Relation Database design and implementation. References to that book are welcome.

    Read the article

  • Using typedefs from a template class in a template (non-member) function

    - by atomicpirate
    The following fails to compile (with gcc 4.2.1 on Linux, anyway): template< typename T > class Foo { public: typedef int FooType; }; void ordinary() { Foo< int >::FooType bar = 0; } template< typename T > void templated() { Foo< T >::FooType bar = T( 0 ); } int main( int argc, char **argv ) { return 0; } The problem is with this line: Foo< T >::FooType bar = 0; ...and the compiler makes this complaint: foo.c: In function ‘void templated()’: foo.c:22: error: expected `;' before ‘bar’ Normally one sees this when a type hasn't been declared, but as far as I can tell, Foo< T ::FooType should be perfectly valid inside templated().

    Read the article

  • Difficulty with MooTools Class.extend

    - by Erin Drummond
    Consider the following code: var Widget = new Class({ Implements: [Options], options: { "name" : "BaseWidget" }, initialize: function(options) { alert("Options are: " + JSON.stringify(options)); //alerts "Options are: undefined" this.setOptions(options); alert("My options are: " + JSON.stringify(this.options)); //alerts "My options are: { 'name' : 'BaseWidget' }" }, getName: function() { return this.options.name; } }); var LayoutWidget = Widget.extend({ initialize: function() { this.parent({ "name" : "Layout" }); } }); alert(new LayoutWidget().getName()); //alerts "BaseWidget" I am having difficulty in determining why the argument passed in the "this.parent()" call in "initialize" function of LayoutWidget is coming through as "undefined" in the initialize function of Widget. I am using MooTools 1.2.2. Would somebody be able to point me in the right direction?

    Read the article

  • Sex - in domain name is this bad???

    - by user3583
    In short I am working with a company that does trade shows... one of their new domain names has the word 'sex' in but completely innocently. EXAMPLE: www. someproductsexpo .com (Being 'some' 'products' 'expo'). The content is completely inoffensive and I do not see there being any other things that would flag either the web or any emails sent from [email protected] as inappropriate. I was just wondering if any has experiences of any domains like this or comments to add? Thanks

    Read the article

< Previous Page | 27 28 29 30 31 32 33 34 35 36 37 38  | Next Page >