|
1 | | -# declarative-cos |
| 1 | +# Welcome to the DeclarativeCOS! |
| 2 | +<br/> |
| 3 | +<br/> |
| 4 | +<br/> |
| 5 | +# What is DeclarativeCOS? |
| 6 | + |
| 7 | +DeclarativeCOS - is another view to programming on the Caché ObjectScript language. It allows you to write the code in declarative style. |
| 8 | +<br/> |
| 9 | +<br/> |
| 10 | +# What is declarative style in COS? |
| 11 | + |
| 12 | +Declarative style in COS means that you write the code as a statement which describes what you need to do. |
| 13 | +<br/> |
| 14 | +<br/> |
| 15 | +# What is the difference from my one-liners code? |
| 16 | + |
| 17 | +The main point is not to add one-liners features to COS. The main point is to bring another kind of mind when you do your task. DeclarativeCOS allows to remove regular loops from your code, because you really don't need it. |
| 18 | +<br/> |
| 19 | +<br/> |
| 20 | +# What is the problem with my regular loops in COS? |
| 21 | + |
| 22 | +Loop is just an instrument to solve the problem. In common, the problem is to traverse by collection and do some action with every element. Do you really need a loop for it? No. You choose a loop because COS supports loops only. DeclarativeCOS allows to write the code in declarative style. Just declare what you want to do and DeclarativeCOS will do all the rest for you. |
| 23 | +<br/> |
| 24 | +<br/> |
| 25 | +# OK. How does it work? |
| 26 | + |
| 27 | +**5 steps:** |
| 28 | +- Extends from DeclarativeCOS.DeclarativeProvider. |
| 29 | +- Implement class method. |
| 30 | +- Mark the method. |
| 31 | +- Use one of provided DeclarativeCOS statements. |
| 32 | +- Enjoy the result. |
| 33 | + |
| 34 | +<br/> |
| 35 | +<br/> |
| 36 | +# Any example, please. |
| 37 | + |
| 38 | +Suppose, we need to output all items of the list (for example, list is instance of [%ListOfDataTypes](http://docs.intersystems.com/latest/csp/documatic/%25CSP.Documatic.cls?PAGE=CLASS&LIBRARY=%25SYS&CLASSNAME=%25Library.ListOfDataTypes)). |
| 39 | + |
| 40 | +**Step 1. Extends from DeclarativeCOS.DeclarativeProvider.** |
| 41 | +``` |
| 42 | +Class MyPackage.IO extens DeclarativeProvider |
| 43 | +{ |
| 44 | +} |
| 45 | +``` |
| 46 | + |
| 47 | +**Step 2. Implement class method.** |
| 48 | +``` |
| 49 | +Class MyPackage.IO extens DeclarativeProvider |
| 50 | +{ |
| 51 | +
|
| 52 | +ClassMethod print(value As %String) |
| 53 | +{ |
| 54 | + w value |
| 55 | +} |
| 56 | +
|
| 57 | +} |
| 58 | +``` |
| 59 | + |
| 60 | +**Step 3. Mark the method.** |
| 61 | +``` |
| 62 | +Class MyPackage.IO extens DeclarativeProvider |
| 63 | +{ |
| 64 | +
|
| 65 | +/// @Declarative("io:print") |
| 66 | +ClassMethod print(value As %String) |
| 67 | +{ |
| 68 | + w value |
| 69 | +} |
| 70 | +
|
| 71 | +} |
| 72 | +``` |
| 73 | + |
| 74 | +**Step 4. Use one of provided DeclarativeCOS statements.** |
| 75 | +``` |
| 76 | +s words = ##class(%Library.ListOfDataTypes).%New() |
| 77 | +d words.Insert("Hello ") |
| 78 | +d words.Insert("World!") |
| 79 | +
|
| 80 | +zforeach $zbind(words, "io:print") |
| 81 | +``` |
| 82 | + |
| 83 | +**Step 5. Enjoy the result.** |
| 84 | +``` |
| 85 | +Hello World! |
| 86 | +``` |
| 87 | +<br/> |
| 88 | +# What is about LICENCE? |
| 89 | + |
| 90 | +MIT License |
| 91 | + |
| 92 | +Copyright (c) 2017 InterSystems Corporation |
| 93 | + |
| 94 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 95 | +of this software and associated documentation files (the "Software"), to deal |
| 96 | +in the Software without restriction, including without limitation the rights |
| 97 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 98 | +copies of the Software, and to permit persons to whom the Software is |
| 99 | +furnished to do so, subject to the following conditions: |
| 100 | + |
| 101 | +The above copyright notice and this permission notice shall be included in all |
| 102 | +copies or substantial portions of the Software. |
| 103 | + |
| 104 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 105 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 106 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 107 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 108 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 109 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 110 | +SOFTWARE. |
0 commit comments